Import Java. util. properties; import javax. mail. address; import javax. mail. bodypart; import javax. mail. message; import javax. mail. messagingexception; import javax. mail. multipart; import javax. mail. session; import javax. mail. transport; import javax. mail. internet. internetaddress; import javax. mail. internet. mimebodypart; import javax. mail. internet. mimemessage; import javax. mail. internet. mimemultipart; public class Javamailtest {public static void main (string [] ARGs) throws messagingexception {string email = "123@qq.com"; properties props = new properties (); props. setproperty ("mail. SMTP. auth "," true "); props. setproperty ("mail. transport. protocol "," SMTP "); Session session1 = session. getdefaultinstance (props); session1.setdebug (true); message = new mimemessage (session1); message. setsubject ("your password has been reset"); bodypart B Odypart = new mimebodypart (); string strtext = "<style type = 'text/CSS '>" + "A: hover {" + "text-Decoration: underline; "+" color: red; "+"} "+" # div1 {"+" width: 640px; "+"} "+" # div2 {"+" text-align: right; "+"} "+" </style> "+" <body> "+" <Div id = 'div1 '> "+" dear # Hello, your password has been successfully reset to 123123, and the new password takes effect immediately. "+" <Br/> "+" log on to "+" <a href = '#'> "+" # "+" </a> "+ ""Platform service ", change the password. This is a notification from the system. Please do not reply directly. "+" <Br/> "+" if you have any other questions, please visit "+" <a href = '#'> "+" # "+" </a> "+" for more help. Please describe your situation in detail to avoid unnecessary losses! "+" <Div id = 'div2'> "+" All rights reserved for NSSD. org "+" </div> "+" </div> "+" </body> "; bodypart. setcontent ("<meta http-equiv = 'content-type' content = 'text/html; charset = UTF-8 '>" + strtext, "text/html; charset = UTF-8 "); // set the type and encoding multipart Mm = new mimemultipart (); mm. addbodypart (bodypart); message. setcontent (mm); message. setsentdate (New Java. util. date (system. currenttimemillis () + 3600*8000); message. setrecipient (message. recipienttype. to, new internetaddress ("##@ 163.com"); message. setfrom (New internetaddress ("##@ 163.com"); transport Transport = session1.gettransport (); transport. connect ("smtp.163.com", 25, "##@ 163.com"," *** "); transport. sendmessage (message, new address [] {New internetaddress (email)}); transport. close ();}}