如下所示 :
prueba de paquete; import javax.mail.internet.internetAddress; import javax.mail.internet.mimemessage; import javax.mail.internet.mimeutility; import javax.mail.session; import javax.mail.MessageingException; import javax.mail.transport; public class SendhtMail {Public statMail smtphost, string from, string to, string stem, string messageText) lanza MessagingException, java.io.unsupportedenCodingException {// Paso 1: configure el sistema de sesión de correo.out.println ("Configuración de la sesión de correo para:" + smtphost); java.util.properties props = new java.util.properties (); propsssetProperty ("mail.smtp.auth", "true"); // 指定是否需要 smtp 验证 props.setProperty ("mail.smtp.host", smtphost); // 指定 smtp 服务器 props.put ("mail.transport.protocol", "smtp"); Session Mailsession = session.getDefaultInstance (accesorios); Mailsession.setDebug (false); // 是否在控制台显示 Debug 信息 // Paso 2: Construya el mensaje System.out.println ("Construyendo mensaje - from =" + from + "a =" + a); Internetaddress fromAddress = new InternetAddress (de); Internetaddress toaddress = new InternetAddress (a); Mimemessage testMessage = new Mimemessage (MailSession); testMessage.setFrom (fromAddress); testMessage.addrecipient (javax.mail.message.recipienttype.to, toaddress); testMessage.setsentDate (nuevo java.util.date ()); testMessage.setSubject (mimeutility.encodetext (sujeto, "GB2312", "b")); testMessage.SetContent (MessageText, "Text/Html; Charset = GB2312"); System.out.println ("Mensaje construido"); // Paso 3: ahora envíe el mensaje Transport Transport = Mailsession.getTransport ("SMTP"); transport.connect (smtphost, "riteng_mes", "ri-heng1234"); transport.sendMessage (testMessage, testMessage.getallRecipients ()); transport.close (); System.out.println ("Mensaje enviado!"); } public static void main (string [] args) {string smtphost = "10.131.119.36"; Cadena de = "[email protected]"; Cadena a = "[email protected]"; String SUMPLAY = "HTML 邮件测试"; // Sujeto Javamail 自动转码 StringBuffer Themessage = new StringBuffer (); Themessage.append ("<h2> <font color = rojo> 这倒霉孩子 </font> </h2>"); theSessage.append ("<hr>"); Themessage.append ("<i> 年年失望年年望 </i>"); Themessage.append ("<table border = '1'> <tr> <td> aaa </td> <td> bbb </td> </tr> <tr> <td> ccc </td> <td> ddd </td> </tr> </table>"); Pruebe {sendhtmlmail.sendMessage (smtphost, de, a, sujeto, thesessage.toString ()); } Catch (javax.mail.messagingException exc) {exc.printstacktrace (); } Catch (java.io.unsupportedenCodingException exc) {exc.printStackTrace (); }}}以上就是小编为大家带来的 java 发送带 html 标签内容的邮件实例代码全部内容了 , 希望大家多多支持武林网 ~