Pure Java Implementation NetEase mailbox send mail __ mail send

Source: Internet
Author: User
Pure Java Implementation NetEase mailbox send mailA mail-sending program based on Java development. Because the use of NetEase's SMTP server, so the sender's mailbox requirements NetEase mailbox. Bo main parental test 126 mailbox and 163 mailbox is valid, yeah mailbox did not test.
Prerequisite Preparation you need to import a jar package linkMail.jar:https://github.com/xxxqiuzh/tools/tree/master/jarpackages/sendmail
Mailbox Open SMTP ServiceLogin NetEase Mailbox (screenshot takes 126 mailbox for example) >> enter "Settings" >> click "Pop3/smtp/imap" >> Select "pop3/smtp service" checkbox >> then follow the prompts. This requires you to set the mailbox client authorization code, be sure to remember.

Source: Dosend.java
Import java.util.Properties;
Import javax.mail.*;

Import javax.mail.internet.*; public class Dosend {private string from = "xxx_qz@126.com";//Sender mailbox Address private String user = "xxx_qz@126.com";//Sender Title, the same email address private String password = "xxxqz126"; Sender Mailbox Client Authorization Code/** * * @param to * @param text * @param title *//* Send authentication Message/public boolean sendMail (St
		Ring to, string text, string title) {Properties props = new properties (); Props.setproperty ("Mail.smtp.host", "smtp.126.com"); Set the properties of the mail server that sends mail (use NetEase's SMTP server here) Props.put ("Mail.smtp.host", "smtp.126.com"); Need to be authorized, that is, the user name and password verification, so as to pass the verification (must have this) props.put ("Mail.smtp.auth", "true"); Build a Session Sessions session = Session.getdefaultinstance (props) with the props object just set up; With this sentence, you can display process information at the console during the sending of the message for debugging and//use (you can see the process of sending the message on the console) Session.setdebug (true); Define a Message object with session mimemessage messages = new MimeMessage (session); Load Sender Address try {message.setfrom (new internetaddress (from)); Message.addrecipient (Message.RecipientType.TO, New internetaddress (to)); Load recipient address Message.setsubject (title); Load header Multipart Multipart = new Mimemultipart (); Add parts of the message to the multipart object, including text content and attachment bodypart Contentpart = new MimeBodyPart ();
			Set the text content of the message contentpart.setcontent (text, "Text/html;charset=utf-8");
			Multipart.addbodypart (Contentpart);
			Message.setcontent (multipart); Message.savechanges (); Save changes transport transport = Session.gettransport ("SMTP"); Connect the server's mailbox Transport.connect ("smtp.126.com", user, password);
			Send the Mail out transport.sendmessage (message, message.getallrecipients ());
		Transport.close ();
			catch (Messagingexception e) {e.printstacktrace ();
		return false;
	return true;
		public static void Main (string[] args) {//test dosend ds = new Dosend (); Ds.sendmail ("917785909@qq.com", "Hello, this is a test email, no need to reply.")
	"," Test Mail "); }
}

screenshot


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.