6. In front of the three types of attachments, we have learned to send general text messages and hypertext messages. Today we will let everyone learn to write three types of accessories to send programs. (Note: Writing interface still uses the front) < % @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% Request.setChacterencoding ("GB2312");%> <% @ page import = "java.util. *, javax.mail. *"%> <% @ page import = "javax.mail.internet. *"%> <% @ page import = "javax.activation. *"%> <% @ PAGE Import = "java.net. *"%>
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); // Give message object Setup sender / recipient / topic / send time InternetDress from = New InternetAddress ("xxf@cafe.com"); message.setfrom (from); internetdress to = new internetdress (TTO); message.settype.to, to) Message.setSubject (TTITLE); Message.setSentDate (new date ()); multipart mm = new mimemultipart (); // New a MIMEMULTIPART object is used to store multiple Bodypart objects // set the letter text content Bodypart MDP = New MimeBodypart (); // Newly built a Bodypart object MDP.SetContent (tcontent, "text / html; charSt = GB2312"); / / to set content and format / encoding mode MM.AddBodypart (MDP) to the Bodypart object; // / Adventip Attachment 1 containing letters content into the MIMEMULTIPART object // sets an attachment 1 of the letter (custom attachment: send the text content to the custom file as an attachment) MDP = New MIMEBODYPART ();