Spring advanced-how to use Java code to implement mail sending (1), springjava

Source: Internet
Author: User

Spring advanced-how to use Java code to implement mail sending (1), springjava
In some projects, such as the invoicing system, an alert message is issued for some inventory insufficiency, and the E-mail sending technology is required for registering users on the recruitment website to verify their email addresses. It may be easy to send emails. Open your browser, log on to your mailbox, write a letter, and send an email? So here we will talk about direct use of Java code to send emails.

Solution 1:

You can directly use SUN's JavaMail to send emails, but the code is very troublesome to write.

If you have handwritten A JavaMail email, you will be aware of the cumbersome api.

Solution 2:

Using apache Email, you can quickly send emails,

For more information, see http://commons.apache.org/email/userguide.html.

Solution 3:

Spring also provides an advanced abstraction layer for sending emails, which shields users from some details of the underlying email system and represents the client responsible for underlying resource processing.

The main package of the Spring mail abstraction layer is org. springframework. mail. It includes the main interface MailSender for sending emails, and the value object SimpleMailMessage. It encapsulates the attributes of simple emails, such as from, to, cc, subject, and text.

The package also contains a checked Exception inheritance tree rooted in MailException, which provides high-level abstraction of underlying mail system exceptions.

 

Development steps: Use Spring mail: 1. Add spring and relevant jar files

 

 

Ii. Spring configuration file Email-163.xml

 

Iii. Junit

 

 

Run successfully, you need to modify the user name and password configuration in the email-163.xml, as well as the content of the setForm in the test file.

 

This article will share with you how spring sends a simple email. Next time I will explain to you how to send attachments, embed html and template files.

 

What are you waiting for? Try it now.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.