Original CN-Java original: javazealot
5. Send the message of the HTML format so-called HTML format, which is a hypertext format. Your email can be written in HTML code. After sending it to the other party, the other party will be information will be a hypertext. Hypertext is more than the pure text. The procedure modified under the basis of the previous example: <% @ Page ContentType = "text / html; charset = GB2312"%> <% Request.setChacTerencoding ("GB2312");%> <% @ Page Import = "java.util. *, javax.mail. *"%> <% @ page import = "javax.mail.internet. *"%>
Send success title> head> <% try {string tto = request.getParameter ("to"); string Ttitle = request.getParameter ("Title"); string tcontent = Request.getParameter ("content"); Properties Props = new Properties (); Props.Put ("mail.smtp.host", "127.0.0.1"); prOPs.put (" Mail.smtp.auth "," true "); session s = session.getInstance (props); s.SetDebug (true); mimeMessage message = new mimeMessage (s); // Set the sender / recipient to the message object person / subject / sender time 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 message objects Bodypar T mdp = new mimebodypart (); // Newly built a Bodypart object MDP.SetContent (tcontent, "text / html; charset = GB2312"); // gives the Bodypart object to set content and format / encoding Multipart mm = New mimemultipart (); // New a MIMEMULTIPART object is used to store BODYPART pairs // (in fact, multiple) mm.addbodypart (MDP); // Add BodyPart to the MimeMultipart object (you can join multiple bodypart) Message.SetContent (mm); // puts MM as message object Message.SAVECHANGES (); Transport Transport = S.GETTRANSPORT ("SMTP"); Transport.Connect ("127.0.0.1", "XXF", "Coffee ");