开发者

JavaMail 1.4.3 sending mail though exchange 2003

I keep getting 550 5.7.1 Unable to relay for someUser@gmail.com

try { Properties 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(fro开发者_开发知识库m));

        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;
    }


you must login into your exchange smtp first.

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();
}

or

change your exchange setting to allow you sending without login

Allowing application servers to relay off Exchange Server 2007 http://msexchangeteam.com/archive/2006/12/28/432013.aspx


Your exchange server probably doesn't allow relaying for the ip from which you are submitting to it? Or it might require authentication before relaying.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜