Package mail; import java. Io. unsupportedencodingexception;
Import java.net. malformedurlexception;
Import java.net. url; import javax. Mail. Internet. mimeutility; import org. Apache. commons. Mail. emailattachment;
Import org. Apache. commons. Mail. emailexception;
Import org. Apache. commons. Mail. htmlemail;
Import org. Apache. commons. Mail. multipartemail;
Import org. Apache. commons. Mail. simpleemail; public class send3 {
Public send3 (){}
// Required jar package 5: commons-email-1.2.jar commons-email-1.2-javadoc.jar
// Commons-email-1.2-sources.jar mail. Jar activation. jar.
Public static void main (string [] ARGs ){
Send ();
} // The POP3 and SMTP server address corresponding to the QQ mailbox is POP3: pop.qq.com;
// SMTP: smtp.qq.com. Refer
Public static void send (){
Try {
Htmlemail email = new htmlemail ();
Email. settls (true );
Email. sethostname ("smtp.qq.com"); // The Name Of The sending server.
Email. setauthentication ("449333333@qq.com", "Mailbox password ");
Email. addto ("lu@yahoo.com.cn", "REC"); // recipient
Email. setfrom ("449333333@qq.com"); // sender
Email. setsubject ("Java mail test"); // Title
Email. setcharset ("gb2312"); // sets charset
Email. setmsg ("this is a test email sent by the Java program with an attachment. "); // Content
// Embed the image and get the content ID
URL;
Url = new URL ("http://img.baidu.com/img/image/ilogob.gif ");
String cid = Email. Embed (URL, "Baidu logo ");
Email. sethtmlmsg ("<HTML> <a href = 'HTTP: // www.baidu.com '> Baidu.com </a> + "\"> <Br> <p> Haha </P>
Email. Send (); // send
System. Out. println ("email sent successfully ");
} Catch (emailexception e ){
E. printstacktrace ();
} Catch (malformedurlexception e ){
E. printstacktrace ();
}
}
}
/*
* Some mailboxes need to enable the POP3/SMTP service, such as the QQ mailbox in this example. During the test, a prompt (sent from the QQ mailbox) is displayed, and the mailbox settings are displayed, enable
*/