Lib:
Http://commons.apache.org/proper/commons-email/example: http://commons.apache.org/proper/commons-email/userguide.html
SMTP configuration for common mailboxesDelete the mail. Activation directory H: \ myeclipse10 \ common \ plugins \ com. genuitec. Eclipse. j2eedt. core_10.5.0.me201207171805 \ data \ libraryset \ ee_5
The first is the preparation phase, which needs to be introduced in the project: mail-1.4.jar, activation-1.1.jar, commons-email-1.2.jar. If j2ee5 is used, you need to find javaee. jar. In myeclipse, use the compression tool to open and delete the mail package and activation package. If it is a jar package, delete the mail directly. jar and activation. jar, back up before deletion. The Reason for deletion is that Apache
The activation. jar and mail-1.4.jar under are inconsistent with those built in Sun. If not deleted, an error is reported.
Import Org. apache. commons. mail. defaultauthenticator; import Org. apache. commons. mail. email; import Org. apache. commons. mail. emailexception; import Org. apache. commons. mail. simpleemail; public class mailtest {Private Static final string host_name = "smtp.gmail.com"; Private Static final int host_port = 587; // Private Static final string host_name = "smtp.qq.com "; // Private Static final int host_port = 25; Private Static final string from_name = "Hu xx"; Private Static final string from_email = "raXXX02@gmail.com "; // Private Static final string from_email = "522XXX3876@qq.com"; Private Static final string from_email_password = "xxxxxxx"; Private Static final string to_email = "raXXXXX02@163.com "; private Static final string charset = "UTF-8"; Private Static final String title = "Email Subject"; Private Static final string message = "this is the information I sent to you from QQ haha "; public static void sendemail () {email = new simpleemail (); email. setcharset (charset); // mail content Character Set email. sethostname (host_name); // server email. setsmtpport (host_port); // port email. setauthenticator (New defaultauthenticator (from_email, from_email_password); // authenticator. setsslonconnect (true); // Security Email. setsubject (title); // theme try {email. setfrom (from_email, from_name); // the sender's email. setmsg (Message); // email. addto (to_email); // recipient email. send ();} catch (emailexception e) {e. printstacktrace () ;}} public static void main (string [] ARGs) {sendemail ();}}