java2db

Send html email in java with cc , bcc , image and attachment



The mail API(Application Programing Interface) helps us to send a html email in java stand alone,as well as web applications.The below example explains that how to design an email with html tags, rather than to send a plain text message .

 Required Jar files :
Send html email in java mail.jar (Download mail.jar ) .

 

Example to send html email in java :

From the above example code we are sending a html email in java with cc , bcc , image and attachments.

Send html email in java Add recipients : primary recipients

Send html email in java Add Carbon Copy (CC): carbon copy to secondary recipients- other interested parties

Send html email in java Add Blind Carbon Copy (BCC) : blind carbon copy to tertiary recipients who receive the message. The primary and secondary recipients cannot see the tertiary recipients.

Send html email in java Add Image to the mail body :

HTML image call :

Send html email in java Add  more images to the mail body :

Instantiate another DataSource object with image URI .

Set different name to Content-ID value(Ex: <imageTwo>).

Finally call it from Html <img> tag. See the example below .

HTML image call :

Send html email in java Add Attachments : We can able to add more than one attachment.

Common SMTP servers :

Mail Service Server Host Port
Gmail smtp.gmail.com 587
Yahoo Mail smtp.mail.yahoo.com 587
Hotmail smtp.live.com 25
Rocketmail smtp.mobile.mail.yahoo.com 25



Related Posts :
How to Connect to Oracle from Liferay portlet ( Java Liferay and Oracle integration )
How to Connect Liferay 7 to PostgreSQL ( Java Liferay portlet and PostgreSQL integration )
How to call C# .Net WCF web service in java SOAP client ( Visual Studio 2013 )
How to call PHP RESTful web service in java client
How to call java SOAP web service in php ( php web service client )
Solution to SSLHandshakeException (skip the certificate for Java and LDAP bind)
Example for (media type) text html in RESTful web service ( Jersey )
Java RESTful web service example in maven using JAX-RS
   [will not be published]



^ <