Java mail simple test program sends HTML data

Source: Internet
Author: User
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 ();}}

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.