gpt4 book ai didi

java - Java Mail中是否有像SpecifiedPickupDirectory这样的配置SMTP?

转载 作者:行者123 更新时间:2023-11-30 01:55:07 26 4
gpt4 key购买 nike

在 .NET 中,我们可以配置输出文件夹电子邮件,而不是像这样发送它们。

<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\mail\"/>
</smtp>
</mailSettings>
</system.net>

是否可以像Java中的SpecifiedPickupDirectory那样配置电子邮件的输出文件夹?

最佳答案

public static void createMessage(String to, String from, String subject, String body, List<File> attachments) {
try {
Message message = new MimeMessage(Session.getInstance(System.getProperties()));
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
message.setSubject(subject);
// create the message part
MimeBodyPart content = new MimeBodyPart();
// fill message
content.setText(body);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(content);
// add attachments
for(File file : attachments) {
MimeBodyPart attachment = new MimeBodyPart();
DataSource source = new FileDataSource(file);
attachment.setDataHandler(new DataHandler(source));
attachment.setFileName(file.getName());
multipart.addBodyPart(attachment);
}
// integration
message.setContent(multipart);
// store file
message.writeTo(new FileOutputStream(new File("c:/mail.eml")));
} catch (MessagingException ex) {
Logger.getLogger(Mailkit.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Mailkit.class.getName()).log(Level.SEVERE, null, ex);
}
}

基于此链接的解决方案 Create an email object in java and save it to file

关于java - Java Mail中是否有像SpecifiedPickupDirectory这样的配置SMTP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54798430/

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