c*****a 发帖数: 808 | 1 在用apache tomcat+jsp
ERROR: Unable to send email. Check Tomcat logs for details.
ERROR MESSAGE: Invalid protocol: null
public static void sendMail(String to, String from,
String subject, String body, boolean bodyIsHTML)
throws MessagingException
{
String mailhost = "smtp.gmail.com";
// 1 - get a mail session
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", mailhost);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");
Session session = Session.getDefaultInstance(props);
session.setDebug(true);
// 2 - create a message
Message message = new MimeMessage(session);
message.setSubject(subject);
if (bodyIsHTML)
message.setContent(body, "text/html");
else
message.setText(body);
// 3 - address the message
Address fromAddress = new InternetAddress(from);
Address toAddress = new InternetAddress(to);
message.setFrom(fromAddress);
message.setRecipient(Message.RecipientType.TO, toAddress);
// 4 - send the message
Transport transport = session.getTransport();
transport.connect("x**[email protected]", "xxxx");
transport.sendMessage(message, message.getAllRecipients());
transport.close();
} | c*****a 发帖数: 808 | 2 tomcat logs
Aug 19, 2012 4:28:10 PM org.apache.catalina.core.ApplicationContext log
INFO: PWrecoverServlet: Unable to send email.
Here is the email you tried to send:
=====================================
TO: X***[email protected]
FROM: e********[email protected]
SUBJECT: PassWord Recovery
Dear XXX,
Your password is XXXX |
|