gpt4 book ai didi

JavaMail 无效的 MSGID

转载 作者:行者123 更新时间:2023-12-01 15:15:03 24 4
gpt4 key购买 nike

我正在运行带有底层 Postfix 服务器的 JBoss 服务器。当我发送电子邮件时,JavaMail 创建一个无效的 messageID,例如消息 ID:<47112553230.139.4972667128159.JavaMail.undefined>。

我使用此代码发送邮件:

Properties props = new Properties();
props.put("mail.smtp.host", "xxx.tld");
props.put("mail.host", "xxx.tld");
InitialContext ictx = new InitialContext(props);
Session sess = (Session) ictx.lookup("java:jboss/mail/Default");
Transport trans = sess.getTransport("smtp");
trans.connect();

MimeMessage msg = new MimeMessage(sess);
msg.setFrom(new InternetAddress(from));
msg.addRecipients(RecipientType.TO, InternetAddress.parse(to, false));
msg.setSubject(subject);
msg.setText(message);
msg.setHeader("Content-Type", "text/html; charset=\"utf-8\"");
msg.saveChanges();

Transport.send(msg, msg.getAllRecipients());
trans.close();

后缀主要配置:

myhostname = xxx.tld
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = xxx.tld, Debian-60-squeeze-64-minimal, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = 127.0.0.1

如何解决这个问题?

最诚挚的问候,克里斯蒂安

最佳答案

这就是我在 @BillShannon 的帮助下解决问题的方法:

Properties props = new Properties();
InitialContext ictx = new InitialContext(props);
Session sess = (Session) ictx.lookup("java:jboss/mail/Default");
props = sess.getProperties();
props.put("mail.smtp.host", "xxx.tld");
props.put("mail.host", "xxx.tld");
props.put("mail.from", "yyy@xxx.tld");
sess = Session.getInstance(props);

关于JavaMail 无效的 MSGID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11736241/

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