A: Preface
Always want to do the Java e-mail features, but has not been successful, special no language Ah, so there is time for me to finally succeed Ah, although the simplest, but still recorded it!
II: Content
The main requirement here is Spring-context-support.jar and Mail.jar, so you can use the frame to build it yourself.
Package Com.wh.graduate.controller;import Org.springframework.mail.simplemailmessage;import Org.springframework.mail.javamail.javamailsenderimpl;import org.springframework.stereotype.controller;@ Controllerpublic class Mailcontroller {public static void main (string[] args) {Javamailsenderimpl Senderimpl = new Javama Ilsenderimpl (); Senderimpl.sethost ("smtp.qq.com"); Senderimpl.setport (+); Senderimpl.setusername ("xx"); Senderimpl.setpassword ("xxx"); Mail message settings simplemailmessage mailmessage = new Simplemailmessage (); Mailmessage.setto ("[email protected]"); Mailmessage.setfrom ("[email protected]"); Mailmessage.setsubject ("First email Oh"); Mailmessage.settext ("Mail test out! "); Send mail senderimpl.send (mailmessage);} }
This bug will be reported initially:
454 authentication failed, please open SMTP flag first!
Baidu after the settlement method:
To turn these services on!
Three: summary
Finally send their own success once, I am, the practice is to test the truth of the best standards!
Java Send mail (i)