So I have a registration form with action to mail.jsp in order to send verification mail. Here is the mail.jsp code
<%@ 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;
} %>
But I get this javax.mail.internet.ParseException
. What cause this exception?
try with using
message.setContent("CONTENT_TYPE_HTML;charset=UTF-8");
instead of;
message.setContent("<h1>Welcome to our site</h1>");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.