gpt4 book ai didi

java - 如何使用 javax.mail 设置或更改 SMTP Message-ID?

转载 作者:太空狗 更新时间:2023-10-29 22:37:41 31 4
gpt4 key购买 nike

如何在使用 javax.mail 发送邮件时设置 SMTP 消息 ID。我的邮件服务器报告如下内容:

1 <= me@domain.com H=mail (host) [192.168.1.4] P=esmtp S=142014
id=2043289758.9.1322829290422.JavaMail.thor@developer.local
2 => sombodey@else R=dnslookup T=remote_smtp H=mx00.t-online.de [194.25.134.8]
3 Completed

我想在发送之前设置 id=2043289758.9.1322829290422.JavaMail.thor@developer.local。这可能吗?它创建的电子邮件是这样的:

Properties props = System.getProperties();
props.put("mail.smtp.host", "192.168.1.4");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);
Message msg = createMsg();
Transport.send(msg);

最佳答案

相信这一段JavaMail FAQ回答你的问题:

Q: I set a particular value for the Message-ID header of my new message, but when I send this message that header is rewritten.

A: A new value for the Message-ID field is set when the saveChanges method is called (usually implicitly when a message is sent), overwriting any value you set yourself. If you need to set your own Message-ID and have it retained, you will have to create your own MimeMessage subclass, override the updateMessageID method and use an instance of this subclass.

class MyMessage extends MimeMessage {
...

protected void updateMessageID() throws MessagingException {
setHeader("Message-ID", "my-message-id");
}
...
}

关于java - 如何使用 javax.mail 设置或更改 SMTP Message-ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8366843/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com