我一直得到550 5.7.1无法转发someUser@gmail.com
尝试{ 属性p = System.getProperties();
p.put("mail.smtp.host", "server IP");
p.put("mail.smtp.port", "25");
p.put("mail.debug", "true");
Session s = Session.getDefaultInstance(p);
Message msg = new MimeMessage(s);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
Multipart mp = new MimeMultipart();
BodyPart bp = new MimeBodyPart();
bp.setText(message);
mp.addBodyPart(bp);
msg.setContent(mp);
Transport t = s.getTransport("smtp");
t.send(msg);
return 0;
} catch (Exception e) {
e.printStackTrace();
return 1;
}
答案 0 :(得分:1)
您必须先登录您的交换smtp。
String host = "smtp.gmail.com;
String username = "user";
String password = "passwd";
Properties props = new Properties();
props.put("mail.smtps.auth", "true");
// ...
MimeMessage msg = new MimeMessage(session);
// set the message content here
Transport t = session.getTransport("smtps");
try {
t.connect(host, username, password);
t.sendMessage(msg, msg.getAllRecipients());
} finally {
t.close();
}
或
更改您的兑换设置,以便您无需登录即可发送
允许应用程序服务器进行中继 关闭Exchange Server 2007 http://msexchangeteam.com/archive/2006/12/28/432013.aspx
答案 1 :(得分:0)
您的交换服务器可能不允许转发您提交给它的IP?或者在转发之前可能需要验证。