1, first register a 163 mailbox
Your e-mail address is [email protected]
The login password is [email protected]***19
e-mail, mail must turn on pop and SMTP service, log in mail
Open Pop service, this time prompted you must set the authorization password, I set here is wy87****
In the code must be set to this authorization password to send mail, cannot be set as a login password
The client needs the following two jar files
Let's look at the code for the program:
Packagecom.weiyuan.test;Importjava.io.IOException;Importjavax.mail.MessagingException;Importjavax.mail.Session;Importorg.junit.Test;ImportCn.itcast.mail.Mail;Importcn.itcast.mail.MailUtils; Public classSendemailtest {/*need to use Mmail and Activation.jar **/@Test Public voidSendEmail ()throwsmessagingexception, ioexception{String host= "smtp.163.com";//QQ e-mail address, port 465 or 587//QQ accepts mail server address is pop.qq.com, Port 995String username= "18780279472";//Login server's accountString password= "wy87***";//This is not the client login password, but the authorization password must pay attention toSession session =mailutils.createsession (host, username, password); //Send mailString from = "[email protected]";//SenderString to = "[email protected]";//RecipientString title = "Test Message"; String content= "<a href= ' http://www.baidu.com ' > Baidu </a>"; Mail Mail=NewMail (from,to,title,content); Mailutils.send (session, mail); }}
Javaweb Online Book Mall complete project--Send mail