JavaMail technology to send mail to ""

Source: Internet
Author: User

11. Import 2 jar packages, Mail.jar,activation.jar22. The imported jar package and the Javax.activation package and Javax.mail conflict in the Java EE javaee.jar in MyEclipse,3 The solution is as follows:4In MyEclipse, click the window-preference-search box to enter LIB, select library sets, select Javaee.jar-add jar/on the rightZIP, then choose to open with a compression program, select the package to remove, click on the compression program above the deletion can! 5 The code is as follows:6  Packagetest;7 8 9 ImportJavax.mail.Message;Ten Importjavax.mail.MessagingException; One Importjavax.mail.PasswordAuthentication; A Importjavax.mail.Session; - ImportJavax.mail.Transport; - Importjavax.mail.internet.AddressException; the Importjavax.mail.internet.InternetAddress; - ImportJavax.mail.internet.MimeMessage; - ImportJavax.mail.internet.MimeMessage.RecipientType; -  +  - ImportJavax.mail.Authenticator; + Importjava.util.Properties; A /** at * Send mail -  * @authorAdmin -  * -  */ -  Public classJavaMail - { in  Public Static voidMain (string[] args)throwsaddressexception, Messagingexception - {  toProperties props =NewProperties (); + //need to set up the sending host for props and whether authentication is required - //props.setproperty ("mail.host", "localhost");//Connected Servers theProps.setproperty ("Mail.host", "smtp.163.com");//Connected Servers *Props.setproperty ("Mail.smtp.auth", "true");//whether certification is required $ Panax Notoginseng  -  the  + //create an Object session ASession session = Session.getinstance (props,NewAuthenticator () the { +  -  $ @Override $ protectedpasswordauthentication getpasswordauthentication () - { - return NewPasswordauthentication ("[Email protected]", "wy5776402287"); the  - Wuyi } the  - }); Wu  - //create an object of a message AboutMessage message =NewMimeMessage (session); $  - //Set Sender -Message.setfrom (NewInternetAddress ("[Email protected]")); - //Set Recipient AMessage.setrecipient (Recipienttype.to,NewInternetAddress ("[Email protected]")); + //set the subject of the message theMessage.setsubject ("An Activation message"); - //set the body of a message $  the //message.setcontent ("Activate mail!", "Text/plan"); theMessage.setcontent ("<a href= ' http://www.baidu.com ' >xxx, this is an activation mail!</a>", "text/html;charset=utf-8");//Add Hyperlink the //Send the transport.send (message); -  in  the } the}

JavaMail technology to send mail to ""

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.