【发布时间】:2016-04-02 02:14:48
【问题描述】:
我可以通过在控制台上输入以下内容从 linux 服务器发送电子邮件,没有任何问题:
mail -s "测试主题" testemail@gmail.com /null
我尝试通过 Java 应用程序发送它,使用 javax.mail 通过:
public void sendMail() throws MessagingException
{
final Properties p = new Properties();
p.put("mail.smtp.host", "localhost");
final Message msg = new MimeMessage(Session.getDefaultInstance(p));
msg.setFrom(new InternetAddress(from));
msg.addRecipient(RecipientType.TO, new InternetAddress(to));
msg.setSubject("Test");
msg.setText(body);
Transport.send(msg);
}
但我得到了一个
原因:com.sun.mail.util.MailConnectException:无法连接到主机,端口:localhost,25;超时 -1
错误,这是我需要更换的原因吗
p.put("mail.smtp.host", "localhost");
我的服务器地址?如果是,我在哪里可以找到我应该放在那里的东西?
谢谢!
【问题讨论】:
标签: smtp jakarta-mail sendmail