其实,我想在我的网页上创建一个超链接。点击该超链接时,它应该打开MS Outlook窗口来发送电子邮件,其中To,From和Subject字段将被动态填充。在Java或Javascript中创建.msg文件[电子邮件]?
到目前为止,我尝试使用Java邮件API,并成功地能够创建.eml文件。我创建了与我的网页上的.eml文件的超链接。但它没有打开MS Outlook,而是它显示在浏览器本身。所以我认为可能与.msg文件它将工作。但我不知道如何创建.msg文件。
这里是代码来创建.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);
}
}
所以请让我知道我可以创建使用Java .msg文件,或者如果您知道任何其他方式来完成我的任务,那么请让我知道。
我被困在这个问题。请帮助。 –
对于那些在Outlook中打开'.eml'文件链接而不是浏览器的人,[看到这个问题](http://stackoverflow.com/questions/9553111/open-eml-file-link-in-outlook-2010 -and-不是浏览器)。看起来它是依赖于客户端的。 – ajp15243
.msg文件怎么样? –