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 ""