sal*_*inx 22
您可以使用以下代码创建eml文件.它可以与雷鸟以及其他电子邮件客户端一起使用:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
EML文件只是纯文本文件.标题通过空行与主体分开.标题看起来像这样:
From: "DR CLEMENT OKON" <drclement@nigerianspam.com>
To: "You" <you@yourdomain.com>
Subject: REQUEST FOR URGENT BUSINESS RELATIONSHIP
Date: Tue, 30 Sep 2008 09:42:47 -0400
Run Code Online (Sandbox Code Playgroud)
有关更多信息,官方规范是RFC 2822.它实际上并不像某些RFC那样难以阅读.
编辑:当我说"纯文本"时,我应该想一下.我真的是指普通的ASCII - 而不是8位"扩展ASCII" - 直到字符127.如果你想要超过7位,你需要某种编码,事情变得复杂.
归档时间: |
|
查看次数: |
31083 次 |
最近记录: |