warm tip: Because the number of messages sent too many, will be officially labeled, so that the mail will be placed in the spam mailbox, the test of the small partners attention!
nonsense not much to say, the following code:
Package com.tpyin.test;
Import java.util.Properties;
Import org.apache.commons.mail.EmailException;
Import Org.apache.commons.mail.HtmlEmail;
/**
*
* @author Cursive Cloud
* Send mailbox Test
* Required JAR Package
*mail.jar
*commons-email-1.1.jar
*
* Precautions:
* Using MyEclipse development may throw exceptions when importing jar packages that conflict with Java EE 5 Libraries mail Packets
*exception in thread "main" Java.lang.noclassdeffounderror:com/mail/util/lineinputstream
At Javax.mail.internet.mimeutility.<clinit> (mimeutility.java:1161)
At Javax.mail.internet.InternetAddress.setPersonal (internetaddress.java:216)
At Org.apache.commons.mail.Email.createInternetAddress (email.java:525)
At Org.apache.commons.mail.Email.setFrom (email.java:600)
At Org.apache.commons.mail.Email.setFrom (email.java:583)
At Com.beauty.common.Sendemail.sendMail (sendemail.java:22)
At Com.beauty.common.Sendemail.main (sendemail.java:45)
*
* Solution: I use the myelipse10 below is 10 for example
* Open MyEclipse installation directory
*e:\myeclipse10\common\plugins\com.genuitec.eclipse.j2eedt.core_10.0.0.me201203160414\data\libraryset\ee_ 5. Open Javaee.jar as a zipped package and delete mail
**/
public class Sendemail {
public static Boolean SendMail (string mailTo, String subject,
String Mailcontext) {
try {
Htmlemail email = new Htmlemail ();//instantiation of
Email.sethostname ("smtp.163.com");//Set the sender's server
Email.setfrom ("[Email protected]", "American Customer China");
Email.setauthentication ("[Email protected]", "954475052");//Parameter comment: Sender's email (account number, password)
Email.addto (MailTo, "customer");//Set Send address
Email.setcharset ("GBK");//Troubleshoot sending content garbled
Email.setsubject (subject);//Send title
Email.sethtmlmsg (Mailcontext);//content sent by mail
Properties props = System.getproperties ();
Setting up a mail server
Props.put ("Mail.smtp.host", "smtp.163.com");
Props.put ("Mail.smtp.auth", "true");
Email.send ();//Send
return true;
} catch (Emailexception e) {
E.printstacktrace ();
return false;
}
}
public static void Main (string[] args) {
String code= "received no, perfect";
String MailTo = "//Set the mailbox to be sent";
String Subject = "Authentication mailbox, let you enjoy the United States and the United States engraved";
String Mailcontext = "You are verifying the mailbox, the CAPTCHA is:" + code;
Boolean m=sendMail (mailTo, subject, mailcontext);
System.out.println (m);
}
}
This article is from the "12241542" blog, please be sure to keep this source http://12251542.blog.51cto.com/12241542/1876580
Java some common questions about sending e-mail share