Create email with recipient, subject, body AND attachment

by baconbacon   Last Updated December 06, 2018 15:26 PM - source

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. 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.

Answers 1

You can open the system's email client using the desktop class.

Desktop.getDesktop().mail( new URI( "mailto:[email protected]" ) )

According to these docs the command you need is

"path/to/Outlook.exe /c ipm.note /a \"path/to/attachment\""

Assemble this and run it via ProcessBuilder

Reference from:

to open outlook mail from java program and to attach file to the mail from directory

Alina Li
Alina Li
December 04, 2018 07:12 AM

Related Questions

Template Based Email Functionality

Updated August 02, 2016 08:12 AM

Do Outlook Add-ins API support event listeners?

Updated March 04, 2019 07:26 AM