Java Mail 中是否有类似SpecifiedPickupDirectory 的配置SMTP?
Is there any configuration SMTP like SpecifiedPickupDirectory in Java Mail?
在 .NET 中,我们可以配置输出文件夹电子邮件,而不是像这样发送它们。
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\mail\"/>
</smtp>
</mailSettings>
</system.net>
是否可以像 Java 中的 SpecifiedPickupDirectory 那样为电子邮件配置输出文件夹?
没有
您可以使用 JavaMail 将文件保存到文件夹中而不是发送它们,例如,通过使用 Message.writeTo 方法。
或者您可以编写一个 JavaMail 传输提供程序,将文件保存到一个文件夹中而不是发送它们。
但是 JavaMail 中没有内置任何东西可以做到这一点。
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);
}
}
基于此的解决方案link
Create an email object in java and save it to file
在 .NET 中,我们可以配置输出文件夹电子邮件,而不是像这样发送它们。
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\mail\"/>
</smtp>
</mailSettings>
</system.net>
是否可以像 Java 中的 SpecifiedPickupDirectory 那样为电子邮件配置输出文件夹?
没有
您可以使用 JavaMail 将文件保存到文件夹中而不是发送它们,例如,通过使用 Message.writeTo 方法。
或者您可以编写一个 JavaMail 传输提供程序,将文件保存到一个文件夹中而不是发送它们。
但是 JavaMail 中没有内置任何东西可以做到这一点。
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);
}
}
基于此的解决方案link Create an email object in java and save it to file