Showing posts with label Mail API. Show all posts
Showing posts with label Mail API. Show all posts

Sending email attachment using mail api with text content

Sending email attachment using mail api with text content
We are going learn about how to sent email with Image ATTACHMENT content.
The Steps are listed below
  • Create EmailAttachment and MultiPartEmailinstance.

  • Set the host name of the server smtp.googlemail.com

  • Set email account details .

  • Set email address for To and From.

  • Set Email subject and attachment of the Email.

  • Finally sending mail

SourceFile: TextEmailAttachment.java Output:
Email sent successfully 

Download:Sending email attachment using Gmail with text content

How to sent html content formatted email using Gmail SSL

How to sent html content formatted email using Gmail SSL
We are going learn about how to sent email with HTML content.
The Steps are listed below
  • Create HtmlEmail instance.

  • Set the host name of the server smtp.googlemail.com

  • Set email account details .

  • Set email address for To and From.

  • Set Email subject and HTML content of the Email.

  • Finally sending mail

SourceFile: HTMLEmailDemo.java Output:
Email sent successfully 

Download: How to sent html content formatted email using Gmail SSL

Commons API-Sending email using Gmail SSL

Commons API-Sending email using Gmail SSL
In this example we will learn about sending text email using GMAIL.
Steps to create a text Email
  • Create Email instance.

  • Set the host name of the server smtp.googlemail.com

  • Set email account details .

  • Set email address for To and From.

  • Set Email subject and content of the Email.

  • Finally sending mail


SourceFile: TextEmail.java Output:
Email sent successfully 

For verification purpose, check in receivers inbox.
Download: Commons API-Sending email using Gmail SSL

Introduction to Apache Commons Email API

In this article we are going learn about how compose and send emails using apache commons api in java.
Commons Email api is designed by apache used for sending email. It is designed on top of the Java Mail APIand simplifies email operations.
Some of the important classes are listed below :
SimpleEmail - It is used for sending basic text based emails.
MultiPartEmail- It is used to send multipart messages. Like text message with attachments either inline or attached.
HtmlEmail - It is used to send HTML formatted emails. It supports both MultiPartEmail allowing attachments and embedded images.
ImageHtmlEmail - It is used to send HTML formatted emails with images.
EmailAttachment - It is a container class used for easy handling of attachments.
It is for use with instances of MultiPartEmail and HtmlEmail.
For environment setup , first we need to download commons-email-1.3.2.jar and mail.jar file and set it in to class path.
Click here to download apache commons email jars.