Sending email with attachment using JavaMail API

Sending email with attachment, JavaMail API provides some useful classes like BodyPart, MimeBodyPart etc.
For better understanding of this example, learn the steps of sending email using JavaMail API first.

For sending the email using JavaMail API, you need to load the two jar files:

  • mail.jar
  • activation.jar
  1. This example send email with attachment through Gmail SMTP .
  2. Before running this example change the fromuser, fromuseremailpassword and recipient email address .
  3. Attachment file name is test.txt, you can add more attachment file if you want. This file must be in your class path or provide the full file path.

 

email-attachment

Gopal Das
Follow me

Gopal Das

Founder at GopalDas.Org
He is a technology evangelist, Salesforce trainer, blogger, and working as a Salesforce Technical Lead. After working in Java based project implementation, he jumped to the Salesforce system on a whim and never looked back. He fell in love with Salesforce’s flexibility, scalability, and power. He expanded his knowledge of the platform and became a Certified App Builder, Administrator, Platform Developer I, SalesCloud Consultant while leading the Salesforce implementation and technology needs. He has worked in a wide variety of applications/services like desktop, web and mobile applications.
Gopal Das
Follow me

Leave a Reply

Your email address will not be published. Required fields are marked *