How to write the code for Java to send mail?
In this issue, the editor will bring you how to write the code for sending email to Java. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Package com.jeeplus.common.utils;import org.apache.commons.mail.HtmlEmail
Public class SendMessage {public static void main (String [] args) {SendMessage sm = new SendMessage (); try {sm.sendEmail ("765826385@qq.com", "java Mail Test", "123456789");} catch (Exception e) {/ / TODO Auto-generated catch block e.printStackTrace ();}} public void sendEmail (String emailAdd,String subject,String body) throws Exception {System.out.println ("send email begin") HtmlEmail email = new HtmlEmail (); / / email.set email.setHostName ("smtp.126.com"); / / set smtp server email.setAuthentication ("bseayin@126.com", "WANGjibo1993520"); / / set smtp server authentication information email.addTo (emailAdd, "reciever") / / set recipient address (multiple recipients can be added) email.setFrom ("bseayin@126.com", "uit-test"); / / Sender + email address email.setSubject (subject); / / set subject email.setCharset ("UTF-8"); email.setHtmlMsg ("+ body+"); / / set delivery content email.send () System.out.println ("end");}}
The above is the editor for you to share the Java email code how to write, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.