Pure Java implementation of mail delivery service (pro-test easy to use)

Source: Internet
Author: User

I tested it today. Using Java code to send a limited number of services is very simple. Direct Post code:

Importcom.sun.mail.util.MailSSLSocketFactory;ImportJavax.mail.*;Importjavax.mail.internet.InternetAddress;ImportJavax.mail.internet.MimeMessage;Importjava.security.GeneralSecurityException;Importjava.util.Date;Importjava.util.Properties; Public classMain { Public Static voidMain (string[] args)throwsmessagingexception, generalsecurityexception {Properties props=NewProperties (); //turn on debug debuggingProps.setproperty ("Mail.debug", "true"); //The sending server requires authenticationProps.setproperty ("Mail.smtp.auth", "true"); //set the mail server host nameProps.setproperty ("Mail.host", "smtp.163.com"); //props.setproperty ("Mail.port", "465"); //Send mail Agreement nameProps.setproperty ("Mail.transport.protocol", "SMTP"); Mailsslsocketfactory SF=Newmailsslsocketfactory (); Sf.settrustallhosts (true); Props.put ("Mail.smtp.ssl.enable", "true"); Props.put ("Mail.smtp.ssl.socketFactory", SF); Session Session=session.getinstance (props); Message msg=NewMimeMessage (session); Msg.setsubject ("Seenews Error"); StringBuilder Builder=NewStringBuilder (); Builder.append ("url =" + "http://blog.csdn.net/never_cxb/article/details/50524571"); Builder.append ("\ nthe page crawler error"); Builder.append ("\ n Time" +NewDate (). GetTime ());        Msg.settext (Builder.tostring ()); Msg.setfrom (NewInternetAddress ("[Email protected]")); Transport Transport=Session.gettransport (); Transport.connect ("Smtp.163.com", "[email protected]", "* * your own e-mail address * *"); Transport.sendmessage (MSG,NewAddress[] {NewInternetAddress ("[Email protected]") });    Transport.close (); }}

This should be OK. Yes, before you have to download the appropriate JAR packages: Activation.jar and Mail.jar.

Pure Java implementation of mail delivery service (pro-test easy to use)

Related Article

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.