Get all updates of Java4s
Follow Us: Email Newsletter

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 MailLogic.java, will show you how..

Files Required

  • ClientLogic.java
  • MailLogic.java
  • spconfig.xml

Jars Required

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

ClientLogic.java

MailLogic.java

spconfig.xml

Output

 

Execution Flow

  • ClientLogic.java 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 java4s.MailLogic.java 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 Author ♦

Java4s_Author
sivateja@java4s.com
Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

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…

    Regards
    A Alam.

  3. Rohit Dabas says:

    Hi Sivateja Kandula,

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

    Thanks a lot.

  4. Ansuman Roy says:

    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

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
Upcoming
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

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