通过配置覆盖Message-ID [英] Override Message-ID by configuration

查看:94
本文介绍了通过配置覆盖Message-ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用默认的WildFly邮件会话从应用程序发送电子邮件时,自动生成的消息ID会表明我的服务器是WildFly:

When I send email from my application using the default WildFly mail session, the auto-generated message ID gives away that my server is WildFly:

Message-ID: <524672585.11.1429091886393.JavaMail.wildfly@myserver.example.com>

出于安全原因,我想禁止或覆盖消息ID中的wildfly子字符串.

For security reasons, I'd like to suppress or override the wildfly substring in the message ID.

是否有配置元素或系统属性可以做到这一点?

Is there a configuration element or a system property to do that?

推荐答案

升级到 JavaMail 1.5.3 .该正式版本具有错误6496 -Message-Id泄漏了Java进程的当前用户/主机名标记为已解决.

Upgrade to JavaMail 1.5.3. That official release has Bug 6496 -Message-Id leaks current user/hostname of the Java process marked as resolved.

否则,Message-ID计算将使用 mail.from 会话属性设置为覆盖包括操作系统用户名在内的会话属性

Otherwise, the Message-ID computation uses the InternetAddress.getLocalAddress method which is including the username. You can set the mail.from session property to override including the O/S user name.

public static void main(String[] args) throws Exception {
        Properties props = new Properties();
        props.put("mail.from", "------@bar.baz");
        Session s = Session.getInstance(props);
        MimeMessage m = new MimeMessage(s);
        m.addFrom(InternetAddress.parse("foo@bar.baz"));
        m.setText("");
        m.saveChanges();
        m.writeTo(System.out);
}

这将输出如下内容:

From: foo@bar.baz
Message-ID: <1688376486.0.1429814480627.JavaMail.------@bar.baz>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

如果您使用默认会话,则只需将"mail.from"添加到系统属性中即可.

If you are using the default session you can just add 'mail.from' to the system properties.

这篇关于通过配置覆盖Message-ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆