【问题标题】:Sending email by servlets通过 servlet 发送电子邮件
【发布时间】:2014-10-19 10:33:42
【问题描述】:
Properties props = new Properties();

props.setProperty("mail.smtps.host", "smtp.gmail.com");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.starttls.enable","true");
props.setProperty("mail.debug", "true");
props.setProperty("mail.smtps.auth", "true");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.setProperty("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.smtp.socketFactory.fallback", "false");

Authenticator auth = new SMTPAuthenticator(login, password);

Session session = Session.getInstance(props, auth);
session.setDebug(true);
try
{     
    MimeMessage msg = new MimeMessage(session);
    msg.setText(message);
    msg.setSubject(subject);
    msg.setFrom(new InternetAddress(from));
    msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

    Transport.send(msg);
}

我正在尝试通过 servlet 发送电子邮件。但是我在这段代码中收到了 MessagingException。而且很可能,这个异常是由 Transport.send(msg) 引发的。我怎样才能摆脱这种情况?

【问题讨论】:

  • 你是否包含相同的 API?
  • 如果我没记错那么属性应该是 System.getprpoerties();

标签: java servlets


【解决方案1】:

如果你不介意使用 java 邮件,那么你可以使用它。试试这个..

http://www.tutorialspoint.com/java/java_sending_email.htm

【讨论】:

    猜你喜欢
    • 2012-03-22
    • 2012-01-07
    • 2012-04-27
    • 2016-07-04
    • 2018-09-19
    • 2021-03-23
    • 2017-05-16
    • 2011-07-14
    相关资源
    最近更新 更多