gpt4 book ai didi

java - 如何使用 Java 邮件 API 保存已发送邮件?

转载 作者:行者123 更新时间:2023-12-01 04:52:33 39 4
gpt4 key购买 nike

如何使用 Javamail API 将已发送的项目保存在邮件中?

props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");

Session session = Session.getInstance(props,new javax.mail.Authenticator() {
protected PasswordAuthenticationgetPasswordAuthentication() {
return new PasswordAuthentication("user id","pwd");
}
});

Message message = new MimeMessage(session);
message.setHeader("X-Priority","1");
message.setFrom(new InternetAddress("user id"));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(Toaddress));

message.addRecipients(Message.RecipientType.CC,InternetAddress.parse(cc));
message.setSubject("Subject");
Multipart multipart = new MimeMultipart();
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("test mail");
Transport.send(message);

最佳答案

使用 Gmail,您无需将其保存在已发送文件夹中,Gmail 会自动为您完成此操作

关于java - 如何使用 Java 邮件 API 保存已发送邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14730384/

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