Send E-mail Apache common-email-1.2.jar package

Source: Internet
Author: User
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 ();}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.