Java Mailbox Send

Source: Internet
Author: User

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
Package sendmail;

Import Java.util.Date;
Import java.util.Properties;
Import Javax.mail.Message;
Import javax.mail.Session;
Import Javax.mail.Transport;
Import javax.mail.internet.InternetAddress;
Import Javax.mail.internet.MimeMessage;

/**
*
* @author HGH
*/
public class SDM {
public static void Main (string[] args) {
System.out.println ("Start success");
try {


int port = 25;

String Server = "smtp.163.com";//mail server mail.cpip.net.cn
String from = "[email protected]";//sender, display sender name
String from = "[email protected]";//sender, display sender name
String user = "[email protected]";//Sender Email Address
String user = "[email protected]";//Sender Email Address
String password = "Nmfsqa6hnv1t91iu";//Password

Establish a session
Properties Props = new properties ();
Props.put ("Mail.smtp.host", server);
Props.put ("Mail.smtp.port", string.valueof (port));
Props.put ("Mail.smtp.auth", "true");
Transport Transport = null;
Session session = Session.getinstance (props);
Building information
Message msg = new MimeMessage (session);
Sender
Msg.setfrom (New InternetAddress (from));


String toList = "[email protected]";
internetaddress[] iatolist = new InternetAddress (). Parse (toList);
Recipient
Msg.setrecipients (Message.RecipientType.TO, iatolist);
Send Date
Msg.setsentdate (New Date ());
Theme
Msg.setsubject ("test title");

Msg.setcontent ("Test Content", "Text/html;charset=utf8"); Content

Mail server for authentication
Transport = Session.gettransport ("SMTP");
Transport.connect (server, user, password);
BLUEBIT_CN is the user name, Xiaohao is the password
Transport.sendmessage (MSG, msg.getallrecipients ()); Send
System.out.println ("Mail sent successfully");

} catch (Exception e) {
E.printstacktrace ();
}
}

}

Java Mailbox Send

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.