gpt4 book ai didi

Java - SimpleMimeMessage 未设置主题

转载 作者:太空宇宙 更新时间:2023-11-04 08:46:31 25 4
gpt4 key购买 nike

我使用 Apache Commons Mail 并发现根本没有使用电子邮件主题(以及字符编码等其他设置):

    props.put("mail.smtp.host", "localhost");
Session s = Session.getInstance(props, null);
s.setDebug(true);

MimeMessage message = new MimeMessage(s);
message.setHeader("Content-Type", "text/plain; charset=UTF-8");
message.addHeader("Content-Transfer-Encoding", "quoted-printable");
message.setFrom(new InternetAddress("me@home.com"));
message.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress("you@abroad.com"));
String subj = MimeUtility.encodeText("");
message.setSubject("my subject with specials äöü");

message.setText("Some text with special äöü");
Transport.send(message);

调试输出显示:

 DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "localhost", port 25, isSSL false
220 mydomain ESMTP Postfix
DEBUG SMTP: connected to host "localhost", port: 25

EHLO MyComputer
250-PIPELINING
250-SIZE 10485760
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "10485760"
DEBUG SMTP: Found extension "VRFY", arg ""
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<me@home.com>
250 2.1.0 Ok
RCPT TO:<you@abroad.com>
250 2.1.5 Ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP: you@abroad.com
DATA
354 End data with <CR><LF>.<CR><LF>

Some text with specials =C3=A4=C3=B6=C3=BC
.
250 2.0.0 Ok: queued as 9F623345F99
QUIT
221 2.0.0 Bye

据我了解,主题应该设置在 SMTP 消息的数据部分。

我该如何解决这个问题?

最佳答案

如果你看一下这个(抱歉有缓存的链接,但 Oracle 似乎已(重新)移动了此链接或其他内容):

Apache Commons 似乎在某种程度上影响了 Java Mail。您提供的示例似乎是发送邮件的标准 Java Mail 方式。那么,您可以尝试:

关于Java - SimpleMimeMessage 未设置主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4209851/

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