JavaMail 1.4.3 通过 Exchange 2003 发送邮件

发布于 2024-10-12 02:50:38 字数 954 浏览 7 评论 0原文

我不断收到 550 5.7.1 无法中继 [电子邮件受保护]

尝试{ 属性 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;
    }

I keep getting 550 5.7.1 Unable to relay for [email protected]

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

东京女 2024-10-19 02:50:38

您必须先登录您的 Exchange 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

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

黑色毁心梦 2024-10-19 02:50:38

您的交换服务器可能不允许中继您提交给它的 IP?或者在中继之前可能需要身份验证。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文