我需要使用java實現下面的邏輯。需要用附件打開ms outlook
- >當我點擊一個按鈕時,MS Outlook需要打開To,CC,Subject和附件。
我們可以使用mailto來做這件事,但如果我們使用mailto,我們不能添加附件。
我需要從共享文件夾添加多個附件到MS Outlook
請幫助我。
使用切換,可以有單個附件,但我需要打開Outlook與2+附件併發送按鈕應該可用,以便用戶可以發送郵件
我需要使用java實現下面的邏輯。需要用附件打開ms outlook
- >當我點擊一個按鈕時,MS Outlook需要打開To,CC,Subject和附件。
我們可以使用mailto來做這件事,但如果我們使用mailto,我們不能添加附件。
我需要從共享文件夾添加多個附件到MS Outlook
請幫助我。
使用切換,可以有單個附件,但我需要打開Outlook與2+附件併發送按鈕應該可用,以便用戶可以發送郵件
使用JavaMail創建一個帶有多部分MIME消息的To,CC,主題和附件。然後,不要傳輸消息調用saveChanges和writeTo,並將電子郵件存儲到文件系統。
有一個undocumented/eml
開關,可用於打開MIME標準格式。例如,outlook /eml filename.eml
有一個記錄的/f
開關,它將打開msg
文件。例如outlook /f filename.msg
x-unsent
可用於切換髮送按鈕。
下面是一個例子,讓你開始:
public static void main(String[] args) throws Exception {
//Create message envelope.
MimeMessage msg = new MimeMessage((Session) null);
msg.addFrom(InternetAddress.parse("[email protected]"));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[email protected]"));
msg.setRecipients(Message.RecipientType.CC,
InternetAddress.parse("[email protected]"));
msg.setSubject("Hello Outlook");
//msg.setHeader("X-Unsent", "1");
MimeMultipart mmp = new MimeMultipart();
MimeBodyPart body = new MimeBodyPart();
body.setDisposition(MimePart.INLINE);
body.setContent("This is the body", "text/plain");
mmp.addBodyPart(body);
MimeBodyPart att = new MimeBodyPart();
att.attachFile("c:\\path to file.attachment");
mmp.addBodyPart(att);
msg.setContent(mmp);
msg.saveChanges();
File resultEmail = File.createTempFile("test", ".eml");
try (FileOutputStream fs = new FileOutputStream(resultEmail)) {
msg.writeTo(fs);
fs.flush();
fs.getFD().sync();
}
System.out.println(resultEmail.getCanonicalPath());
ProcessBuilder pb = new ProcessBuilder();
pb.command("cmd.exe", "/C", "start", "outlook.exe",
"/eml", resultEmail.getCanonicalPath());
Process p = pb.start();
try {
p.waitFor();
} finally {
p.getErrorStream().close();
p.getInputStream().close();
p.getErrorStream().close();
p.destroy();
}
}
你必須處理清理電子郵件客戶端關閉後。
您還必須考慮保留在文件系統上的電子郵件的安全含義。
爲什麼要使用Outlook? – Stefan
http://stackoverflow.com/questions/248569/starting-outlook-and-having-an-email-pre-populated-from-command-line – jmehrens
@stefan - 用戶需要前景,因爲他們正在使用 – Thomas