Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to write the code for Java to send mail?

Shulou Source: shulou.com Published: 2022-06-01 18:36:10 09月19日 Update

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.

Tags: Email content code address recipient server analysis service professional small and medium subject information rich content sender multiple that is articles more knowledge articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL MariaDB Shulou Tech Info Huawei vpn