The
looks like this:
Package test;
Import javax.mail.internet.InternetAddress;
Import Javax.mail.internet.MimeMessage;
Import javax.mail.internet.MimeUtility;
Import javax.mail.Session;
Import javax.mail.MessagingException;
Import Javax.mail.Transport; public class Sendhtmlmail {public static void SendMessage (String smtphost, string from, String to,string subject, Strin G MessageText) throws Messagingexception, java.io.UnsupportedEncodingException {//step 1:configure The Mail
Session System.out.println ("Configuring Mail Sessions for:" + smtphost);
Java.util.Properties props = new Java.util.Properties (); Props.setproperty ("Mail.smtp.auth", "true");//Specify whether SMTP authentication Props.setproperty ("Mail.smtp.host", smtphost) is required;
Specifies the SMTP server props.put ("Mail.transport.protocol", "SMTP");
Session mailsession = session.getdefaultinstance (props); Mailsession.setdebug (FALSE)//Whether debug information is displayed on the console//step 2:construct the message System.out.println ("Constructing Message-from= "+From + "to=" + to);
InternetAddress fromaddress = new internetaddress (from);
InternetAddress toaddress = new internetaddress (to);
MimeMessage testMessage = new MimeMessage (mailsession);
Testmessage.setfrom (fromaddress);
Testmessage.addrecipient (Javax.mail.Message.RecipientType.TO, toaddress);
Testmessage.setsentdate (New Java.util.Date ());
Testmessage.setsubject (Mimeutility.encodetext (Subject, "gb2312", "B"));
Testmessage.setcontent (MessageText, "text/html;charset=gb2312");
SYSTEM.OUT.PRINTLN ("message constructed");
Step 3:now Send the message transport transport = Mailsession.gettransport ("SMTP");
Transport.connect (SMTPHost, "Riteng_mes", "ri-teng1234");
Transport.sendmessage (TestMessage, testmessage.getallrecipients ());
Transport.close ();
SYSTEM.OUT.PRINTLN ("message sent!");
public static void Main (string[] args) {String smtphost = "10.131.119.36";
String from = "Riteng_Mes@casetekcorp.com"; String to = "Qiang1_Zhang@intra.casetekcorp.com"; String subject = "HTML mail test";
Subject JavaMail Automatic transcoding stringbuffer themessage = new StringBuffer ();
Themessage.append ("
The above is a small series of Java to send you with HTML tag content of the mail instance code all content, I hope that we support cloud-Habitat Community ~