简体   繁体   English

创建包含收件人、主题、正文和附件的电子邮件

[英]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 .请注意,在字符串subjectbody ,字符% " & / ? \\必须使用百分比编码进行编码

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.

相关问题 我将如何创建用于发送电子邮件的函数,其参数设置为String from,String to,String Subject和String body? - How would I create the function for sending an email with the parameters set as String from, String to, String Subject, and String body? 在Spring Boot管理员警报中自定义电子邮件主题和正文 - Customize the email subject and body in Spring boot admin alert 要从以下文本中提取电子邮件的主题,主题和正文: - want to extract subject, to and body of an email from a text which are separated by : Java邮件:以.htm文件附件以及附件和正文的形式接收电子邮件正文 - Java mail : receiving email body as .htm file attachment along with attachment and body 电子邮件中html正文中的嵌入式图像(嵌入式)(显示为附件) - Embedded images (inline) within html body in email showing as attachment 我想将excel(xls / xlsx)文件嵌入电子邮件正文(而非附件)中 - I want to embed an excel(xls/xlsx) file in an email body(not attachment) Java电子邮件附件在正文中作为纯文本发送 - java email attachment being sent as plain text in body 如何使 XML 字符串资源 email 可点击 TextView 上的预定义主题和正文 - How to make XML string resource email clickable with predefined Subject and Body on TextView 如何即时创建 pdf 文件并将其设为电子邮件附件? - How to create a pdf file on the fly and make it an email attachment? 从 Java 中的 contentBytes 创建 Aspose.Email 附件 - Create Aspose.Email attachment from contentBytes in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM