【发布时间】:2013-12-09 09:06:04
【问题描述】:
我已经在 windows 2008 r2 服务器上安装了 SMTP 服务器和 IIS Web 服务器。我正在尝试通过 localhost 使用 java 代码发送测试电子邮件,但我无法发送电子邮件我收到以下错误,不确定我做错了什么。除了安装 SMTP 服务器,还有什么我需要做的设置,因为我刚刚安装了我的 smtp 服务器并期望这个代码可以工作?
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for marshell@gmail.com
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1862)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1118)
at javax.mail.Transport.send0(Transport.java:195)
at javax.mail.Transport.send(Transport.java:124)
at LotusNotes.SendEmail.main(SendEmail.java:30)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for marshell@gmail.com at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1715)
Java 代码:
public static void main(String[] args) {
String to = "marshell@gmail.com";
String from = "imrmsmtpmail";
String host = "localhost";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Subject Line!");
message.setText("Test email!");
Transport.send(message);
System.out.println("Sent message successfully....");
}
catch (MessagingException mex) {
mex.printStackTrace();
}
}
【问题讨论】:
-
SMTP server response: 550 5.7.1 Unable to relay in - Sending email to a non-company address 的可能重复项 --- 不同的语言,相同的问题。
-
您的 smtp 服务器是否允许向其他域发送电子邮件?
-
嗨 Jonathon,我尝试了我的工作电子邮件 ID,但它仍然给我同样的错误?
-
嗨 Askappy,我启用了中继限制,导致我无法发送指定列表以外的电子邮件,并且列表为空。我只是通过添加到列表来修复它。非常感谢
标签: java windows-server-2008-r2