获得验证邮件jsp的例外

时间:2014-12-17 12:24:18

标签: java jsp email

所以我有一个注册表单,其中包含对mail.jsp的操作以发送验证邮件。这是mail.jsp代码

<%@ page import="java.io.*,java.util.*,javax.mail.*"%>  
<%@ page import="javax.mail.internet.*,javax.activation.*"%>  
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>                                                                                                                                                          
<%@ page contentType="text/html; charset=UTF-8" %> 
<% String result;

String to = request.getParameter("email"); //who gets the mail   

String from = "mymail@gmail.com";                                                                                               
String host = " smtp.gmail.com";     

Properties properties = System.getProperties();

properties.setProperty("mail.smtp.host", host);

Session mailSession = Session.getDefaultInstance(properties);
 try{                                                                                                                       
 MimeMessage message = new MimeMessage(mailSession);
   message.setFrom(new InternetAddress(from));
   message.addRecipient(Message.RecipientType.TO,
                           new InternetAddress(to));
  // Set Subject: header field
  message.setSubject("This is the Subject Line!");
  // Send the actual HTML message, as big as you like
  message.setContent("<h1>Welcome to our site</h1>"); 
  // Send message
  Transport.send(message);
  result = "Sent message successfully....";
  }catch (MessagingException mex) {
  mex.printStackTrace();
  result = "" +mex;
 }  %> 

但我明白了 javax.mail.internet.ParseException。造成这种异常的原因是什么?

1 个答案:

答案 0 :(得分:0)

尝试使用

message.setContent("CONTENT_TYPE_HTML;charset=UTF-8");

而不是;

message.setContent("<h1>Welcome to our site</h1>");