Javax.mail sending mail

Source: Internet
Author: User
Tags email account

   /*  @param  fromMail   Send mailbox     *  @param  user    email account     *  @param  password   email password     *   @param  toMail   receive email     *  @param  mailTitle   message headers     *  @param  mailContent   Email     *  @throws  Exception     */    public static void  SendMail (String frommail, string user, string password, string tomail,  string mailtitle, string mailcontent)  throws Exception {         mailsslsocketfactory sf = new mailsslsocketfactory ();         sf.settrustallhosts (True);         properties prOps = new properties ();         props.put (" ", " mail.*****.com ");         props.put (" Mail.smtp.port ",  465);         props.put (" Mail.transport.protocol " ,  "SMTP");         props.put ("Mail.smtp.auth",  "true");         props.put ("mail.smtp.ssl.enable",  "true");         props.put ("Mail.smtp.ssl.socketFactory",  SF);         session session = session.getinstance (props);         mimemessage message = new mimemessage (session);         message.setfrom (New internetaddress (frommail));         message.setrecipient (MessaGe., new internetaddress (tomail));         Message.setsubject (Mailtitle);         message.settext (mailContent);         message.setsentdate (New date ());         message.savechanges ();        transport  Transport = session.gettransport ();         transport.connect (User, password);         transport.sendmessage (message,  Message.getallrecipients ());         transport.close ();     }

Here are the packages you need to add:

<dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <versio N>1.4.7</version></dependency>

Javax.mail sending mail

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: 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.