错误:com.sun.mail.smtp.smtpsendfailedexception:451 4.3.0错误:队列文件写入错误

发布于 2025-02-04 09:28:21 字数 1332 浏览 1 评论 0原文

我试图在代码下执行执行。

public class Sendmail {
    public static void main(String[] args) {
        String to = "[email protected]";
        String from = "[email protected]";
        Properties properties = System.getProperties();
        properties.put("mail.smtp.host", "smtp.office365.com");
        properties.put("mail.smtp.port", "25");
        Session session = Session.getInstance(properties);
        try {
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setSubject("TEXT!");
            message.setText("The message is here");
            System.out.println("Sending");
            Transport.send(message);
            System.out.println("Sent message successfully");
        } catch (MessageException mex) {
            mex.printStackTrace();
        }
    }
}

当我尝试运行上述程序时,我在transport.send.send(message)行中获得了队列文件写入错误。谁能帮助我解决这个问题?我的代码有任何问题,还是服务器问题?

I have tried to execute below the code.

public class Sendmail {
    public static void main(String[] args) {
        String to = "[email protected]";
        String from = "[email protected]";
        Properties properties = System.getProperties();
        properties.put("mail.smtp.host", "smtp.office365.com");
        properties.put("mail.smtp.port", "25");
        Session session = Session.getInstance(properties);
        try {
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setSubject("TEXT!");
            message.setText("The message is here");
            System.out.println("Sending");
            Transport.send(message);
            System.out.println("Sent message successfully");
        } catch (MessageException mex) {
            mex.printStackTrace();
        }
    }
}

When I tried to run the above program I got queue file write error in Transport.send(message) line. Can anyone please help me to solve this issue? Are there any issues with my code or is this a server problem?

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

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

发布评论

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

评论(1

物价感观 2025-02-11 09:28:21

我认为问题是您的邮件属性是错误的。

尝试将“ mail.transport.protocol”属性设置为“ SMTP”。您当前的道具假设该协议为“ SMTP” 。如果不是,则将忽略“ mail.smtp.host”和“ mail.smtp.port”属性,而将使用默认的主机和端口。

我的怀疑是,在您的情况下,主机默认为“ localhost” ...而您正在运行的Java应用程序的机器未配置为 receion 电子邮件。 (有人提示主机已安装后修复,但这可能是错误的。)

I think that the problem is that your mail properties are wrong.

Try setting the "mail.transport.protocol" property to "smtp". Your current props assume that the protocol is defaulting to "smtp". If it doesn't then the "mail.smtp.host" and "mail.smtp.port" properties will be ignored, and default host and port will be used instead.

My suspicion is that in your case the host is defaulting to "localhost" ... and that the machine you are running the Java application on is not configured to receive email. (There are hints that the host has Postfix installation, but that could be wrong.)

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