发送邮件时出错

时间:2010-11-29 19:25:05

标签: java email javax.mail

我有以下内容......

  Properties prop = new Properties();
  prop.put(host, "localhost");
  prop.put(host, "25");

当我运行以下内容时,它会抛出以下错误...

javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; nested exception is:

java.net.ConnectException: Connection refused

我真的不明白为什么它会把我扔回去......任何人有什么想法?事实上,我的smtp服务器正常工作并且正常工作:S

编辑:如果我理解正确,那就是我的机器......为什么?它应该不是......它意味着要成为host

1 个答案:

答案 0 :(得分:4)

我认为您具有设置主机不正确的属性:

prop.put(host, "localhost");

这将使用主机中的任何键创建一个属性,并将其命名为localhost。我猜你的属性不是你认为的那样,所以JavaMail然后使用默认的localhost。

你可能会想要这个:

 props.put("mail.smtp.host", host);
 props.put("mail.smtp.port", port);
相关问题