How do I set or change the SMTP Message-ID with javax.mail?(如何使用 javax.mail 设置或更改 SMTP 消息 ID?)
问题描述
如何在使用 javax.mail
发送邮件时设置 SMTP 消息 ID.我的邮件服务器报告如下内容:
How can I set the SMTP message-id while sending mails with javax.mail
. My mail server is reporting something like this:
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
.这可能吗?它创建的电子邮件是这样的:
I want to set the id=2043289758.9.1322829290422.JavaMail.thor@developer.local
before sending it. Is this possible? The email it created like this:
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 常见问题解答 回答您的问题:
I believe this section of the JavaMail FAQ answers your question:
问:我为我的新消息的 Message-ID 标头设置了一个特定值,但是当我发送此消息时,标头被重写.
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.
答: 在调用 saveChanges 方法时会为 Message-ID 字段设置一个新值(通常在消息被已发送),覆盖您自己设置的任何值.如果您需要设置您的拥有 Message-ID 并保留它,您必须创建自己的MimeMessage 子类,覆盖 updateMessageID 方法并使用这个子类的实例.
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");
}
...
}
这篇关于如何使用 javax.mail 设置或更改 SMTP 消息 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 javax.mail 设置或更改 SMTP 消息 ID?
基础教程推荐
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01