2013-06-20 90 views
0

其实,我想在我的网页上创建一个超链接。点击该超链接时,它应该打开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文件,或者如果您知道任何其他方式来完成我的任务,那么请让我知道。

+0

我被困在这个问题。请帮助。 –

+0

对于那些在Outlook中打开'.eml'文件链接而不是浏览器的人,[看到这个问题](http://stackoverflow.com/questions/9553111/open-eml-file-link-in-outlook-2010 -and-不是浏览器)。看起来它是依赖于客户端的。 – ajp15243

+0

.msg文件怎么样? –

回答

0

难道你只想要一个mailto link?你不能控制它打开的邮件客户端(毕竟,用户可能没有Outlook),还有一些其他的功能问题,但这听起来像你正在寻找的东西。

+0

我在我公司的内联网上创建网页,这里每个人都有MS Outlook.Your解决方案的工作,如果以某种方式我强制打开MS Outlook中的链接only.Anyway谢谢你的答案。 –

相关问题