Spring Send Email With Attachment Using Gmail SMTP – Example

Spring » on Dec 11, 2012 { 12 Comments } By Sivateja

We know how to send a plane spring E-mail i mean without any attachments, Let us see how to send spring E-mail with attachment which is a similar application just like plane one, but with little modifications in, will show you how..

Files Required

  • spconfig.xml

Jars Required

  • activation.jar
  • classes12.jar
  • commons-email-1.0.jar
  • mail.jar




Execution Flow

  • is our main class, and we are calling id2 [line number 15]
  • So come to spconfig.xml and check line number 23, we are calling having property mail of type JavaMailSender Interface (provided by spring), so it will moves to JavaMailSenderImpl (id1, implemented class of JavaMailSender) and there we have given all the Email related credentials
  • JavaMailSender contains mail() method to send a mail
  • JavaMailSender‘s mail() method contains MimeMessage class object as parameter, like mail(MimeMessage Object)
  • Finally we set From,To,Subject,Msg and called send() that’s it

How simple its is ? :-)

You Might Also Like

  ::. About the Author .::

- Full Stack Java/J2EE & UI Web Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


12 Responses to “Spring Send Email With Attachment Using Gmail SMTP – Example”
  1. shankar says:

    gr8 work .
    easy to understand for newcomer

  2. alam says:

    what is use of cloning plz specify any one…

    A Alam.

  3. Hi Sivateja Kandula,

    I have gone through the complete tutorial. It is very helpful to me.

    Thanks a lot.

  4. How to do that for an email Id with 2 way verification on?

  5. jagadeesh says:

    Hi Teja,

    Thanks for your Tutorial,keep up the good work.

  6. Shaila Addagatla says:

    Hey Sivateja Kandula,

    Thank you for your tutorial.
    They are amazing :) :)

  7. please add the spring security concept(total) in spring framework

  8. Rajesh Kota says:

    Hello Java4s,

    Its an awesome web content for beginners….! halts off to you…! :)

  9. Ram says:

    Good article…

  10. Indraj says:

    Hello Java4s,

    Its an awesome web content for beginners….! keep it up

  11. rajeshwaru says:

    its really simple and helpful.. thank you so much :)

  12. Abhilash says:

    i feel it will be really better, when you create a youtube channel and start posting videos of the concepts


By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Hibernate Spring Struts
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2018 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.