How to Send Word Document in Email using Java

In this brief topic you will understand, how to send Word Document in email using Java. You can easily convert the source file to MHTML format and specify the email settings to send the email in any common operating system like MS Windows, Ubuntu, or macOS using simple API calls.

Steps to Send Word Document in Email using Java

  1. Add Aspose.Words and Aspose.Email JAR file reference from the Maven repository
  2. Instantiate a Document Class object to load the input document for sending email
  3. Specify different SaveOptions to save file in MHTML format to save data into a stream
  4. Load the file using MailMessage class
  5. Initialize SMTP client to configure email message
  6. Send email message containing the word document

In these steps, first of all we load the input Word document in DOCX or DOC file format. Then it is converted to MHTML file using the stream object, which is loaded as an input file for sending the email. Finally, we specify the configuration properties like sender, subject, port to send the email message.

Code to Send DOCX in Email with Java

In the code snippet above, we have loaded the source DOCX file while using an object of the Document class. It is then converted to MHTML file using streams that is to be later processed by Aspose.Email. Then we set different preferences for sending the email message like email to, email from, subject and host settings to control email message properties. This enables you to automate email sending feature and send document in email with Java.

Previously, we learned about how to convert Word to Markdown using Java. Whereas, in this topic we focused on rendering DOCX to TIFF. Whereas, in this topic, we have learnt how using Java send Word Document in Email.