The so-called HTML format, is hypertext format. Your mail can be written in HTML code, sent to each other, the other side will receive the message will be hypertext, hypertext than plain text more beautiful. The following is a modified procedure based on previous examples:
Set sender/Recipient/subject/letter time to a Message object
InternetAddress from=new internetaddress ("xxf@cafe.com");
Message.setfrom (from);
InternetAddress to=new internetaddress (tto);
Message.setrecipient (message.recipienttype.to,to);
Message.setsubject (Ttitle);
Message.setsentdate (New Date ());
Set content for a Message object
BodyPart mdp=new MimeBodyPart ()//Create a new BodyPart object that holds the contents of the letter
Mdp.setcontent (tcontent, "text/html;charset=gb2312")//set content and Format/encoding for BodyPart objects
Multipart mm=new Mimemultipart ()//Create a new Mimemultipart object to store BodyPart
Like (in fact, can be stored in multiple)
Mm.addbodypart (MDP)//Add BodyPart to Mimemultipart object (multiple bodypart can be added)
Message.setcontent (mm);//mm as the content of the Message object
Message.savechanges ();
Transport Transport=s.gettransport ("SMTP");
Transport.connect ("127.0.0.1", "xxf", "coffee");
Transport.sendmessage (Message,message.getallrecipients ());
Transport.close ();
%>
<div align= "center" >
<p><font color= "#FF6600" > Sent successfully!</font></p>
<p><a href= "recmail.jsp" > Take a look at my mailbox </a><br>
<br>
<a href= "index.htm" > re-send a letter </a> </p>
</div>
<%
}catch (Messagingexception e) {
Out.println (E.tostring ());
}
%>
</body>
Note: The HTML file for composing the message is still the same as the one in front (please refer to JSP and Java Mail (c)), and there is no need to make any changes.
How about this program is very simple? If there is anything you don't understand, please leave a message below. Next time we will talk about how to send attachments.
adjourned
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.