[英]Create email with recipient, subject, body AND attachment
I've been working on an email generating program and I am able to generate an email that has either an attachment upon generation using我一直在开发一个电子邮件生成程序,我能够生成一封电子邮件,该电子邮件在生成时带有附件
ProcessBuilder p=new ProcessBuilder("C:\\Program Files (x86)\\Microsoft Office\\Office16\\OUTLOOK.EXE","/a","C:\\BackupData.docx");
or a generated email with the recipient, subject, and body filled out using或使用填写的收件人、主题和正文生成的电子邮件
URI msg = new URI("mailto", mailer+"&subject="+subject+"?body="+body, (String) null);
My issue is that I cannot figure out a way to generate an Outlook email that has both of these features.我的问题是我无法找到一种方法来生成具有这两个功能的 Outlook 电子邮件。 If there is some way to combine these to create an email with attachment, and populated subject & body, I would like to know how to do that.
如果有某种方法可以将这些结合起来创建带有附件的电子邮件,并填充主题和正文,我想知道如何做到这一点。
new ProcessBuilder("C:\\Program Files (x86)\\Microsoft Office\\Office16\\OUTLOOK.EXE",
"/c", "ipm.note", // create new e-mail message
"/m", mailer + "?subject=" + subject + "&body=" + body, // set recipient, subject and body
"/a", "C:\\BackupData.docx"); // attach file
This will start Outlook, open a new e-mail with recipient, subject, and body populated and the file added as attachment.这将启动 Outlook,打开一封包含收件人、主题和正文的新电子邮件,并将文件添加为附件。
Beware that in the strings subject
and body
the characters % " & / ? \\
have to be encoded using percent encoding .请注意,在字符串
subject
和body
,字符% " & / ? \\
必须使用百分比编码进行编码。
You can open the system's email client using the desktop class.您可以使用桌面类打开系统的电子邮件客户端。
Desktop.getDesktop().mail( new URI( "mailto:address@somewhere.com" ) )
According to these docs the command you need is根据这些文档,您需要的命令是
"path/to/Outlook.exe /c ipm.note /a \\"path/to/attachment\\"" "path/to/Outlook.exe /c ipm.note /a \\"path/to/attachment\\""
Assemble this and run it via ProcessBuilder组装它并通过ProcessBuilder运行它
Reference from:参考资料:
to open outlook mail from java program and to attach file to the mail from directory 从java程序打开outlook邮件并将文件附加到来自目录的邮件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.