【发布时间】:2013-06-16 16:52:09
【问题描述】:
实际上,我想在我的网页上创建一个超链接。单击该超链接后,它会打开 MS Outlook 窗口以发送电子邮件,其中将动态填充收件人、发件人和主题字段。
到目前为止,我尝试使用 Java Mail 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文件链接的用户,see this question。看起来它依赖于客户端。 -
.msg 文件呢?
-
我发布该评论和链接是为了让其他人知道试图让
.eml文件正常工作可能是一个失败的原因,应该专注于另一种解决方案,例如制作.msg文件。如何做到这一点,我完全不知道。
标签: java email hyperlink outlook jakarta-mail