【问题标题】:Sending email in Java? [closed]用 Java 发送电子邮件? [关闭]
【发布时间】:2013-01-07 13:13:21
【问题描述】:

谁能推荐一个用 Java 发送电子邮件的库?

【问题讨论】:

标签: java email


【解决方案1】:

试试Commons Mail。这是在 Java Mail API 的基础上构建的,但使用起来更加简单。

【讨论】:

  • 嘿,普通邮件可以与 gmail smtp 服务器一起使用吗?
  • 它适用于任何 smtp 服务器,就像任何邮件客户端一样。
【解决方案2】:

您可能还想看看Apache Commons Email library。它功能强大且易于使用。

你可以按照以下方式做一些事情:

import org.apache.commons.mail.SimpleEmail;
...
String[] recipients = {"a@foo.com", "b@foo.com"};

SimpleEmail email = new SimpleEmail();
email.setHostName("mail.myserver.com");

for (int i = 0; i < recipients.length; i++)
{
    email.addTo(recipients[i]);
}

email.setFrom("me@apache.org", "Me");
email.setSubject("Test message");
email.setMsg("This is a simple test of commons-email");
email.send();

示例代码取自 Commons 电子邮件示例页面,经过修改以显示添加多个收件人。希望对您有所帮助。

【讨论】:

  • 嘿,这可以与 gmail smtp 服务器一起使用吗?
  • 您需要正确验证,但完成后,您可以将其与 gmail 一起使用
【解决方案3】:

【讨论】:

    【解决方案4】:

    我认为最好使用JavaMail API,您可以从以下教程Fundamentals of the JavaMail API获得一些基本知识

    【讨论】:

      猜你喜欢
      • 2012-05-23
      • 2012-08-13
      • 1970-01-01
      • 2016-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      相关资源
      最近更新 更多