Organize Java mail sending API

Source: Internet
Author: User

Http://www.javaeye.com/topic/49031

In the past few days, a project was designed to use a large number of email sending APIs, So I sorted out the scatteredCodeAnd organize it into a class. We hope to use it for comrades who need it.
Define a mail configuration file to facilitate configuration modification,ProgramYou only need to read this configuration file, so that you do not need to modify it later.Source code

Java code
  1. /** 
  2. * Provide the email address. 
  3. */
  4. Public StaticString host_mail_name =Xxx@teesoo.com";
  5. /** 
  6. * Provide the email address. 
  7. */
  8. Public StaticString host_mail_password ="XXX";
  9. /** 
  10. * Email sending protocol 
  11. */
  12. Public StaticString SMTP ="Mail.teesoo.com";
  13. /** 
  14. * Email receiving protocol 
  15. */
  16. Public StaticString POP3 ="Mail.teesoo.com";

Email sending API

Java code
  1. Public Static VoidSend (string to, string subject, string body)ThrowsException {
  2. Mailer mail =NewMailer (manageconfig. SMTP );
  3. Mail. setnamepass (manageconfig. host_mail_name, manageconfig. host_mail_name );
  4. Mail. setfrom (manageconfig. host_mail_name );
  5. Mail. setsubject (subject );
  6. Mail. setbody (body,False);
  7. Mail. setto ();
  8. Mail. setneedauth (True);
  9. Mail. sendout ();
  10. }

I wrote a lot of food, but I sent it.

Src.rar
Description:
Download
File Name: Src.rar
File Size: 3 KB
Downloaded: File downloaded or viewed 197 times

 

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.