There is mail technology in Java. Use spring's mail to simplify your code
The demo code on the Spring Mail API, the annotation on the code is enough to explain everything, actually this is a very simple technology ....
Package org.mail.test;
Import Java.io.File;
Import java.util.Properties;
Import Javax.mail.internet.MimeMessage;
Import Org.springframework.core.io.FileSystemResource;
Import Org.springframework.mail.javamail.JavaMailSenderImpl;
Import Org.springframework.mail.javamail.MimeMessageHelper;
public class Springmail {private static String host = "smtp.qq.com";
The destination mailbox writes the mailbox address that you want to send private static String to = "";
Send a mailbox write your own email address to send ... private static String from = "";
User name private static String username = "";
Password private static String password = "";
Message subject private static String subject = "Test message subject ...";
private static Properties Prop = new properties ();
static {Prop.put ("Mail.smtp.auth", "false");
Prop.put ("Mail.smtp.timeout", "25000");
Prop.put ("Mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
Prop.put ("Mail.smtp.port", 465); public static void Main (string[] args) throws Exception {Javamailsenderimpl JavamailsenderiMPL = new Javamailsenderimpl ();
MimeMessage mimemessage = Javamailsenderimpl.createmimemessage ();
Javamailsenderimpl.sethost (host);
Javamailsenderimpl.setusername (username);
Javamailsenderimpl.setpassword (password);
Mimemessagehelper mimemessagehelper = new Mimemessagehelper (mimemessage,true, "utf-8");
Mimemessagehelper.setfrom (from);
Mimemessagehelper.setsubject (subject);
Mimemessagehelper.settext ("", true);
Mimemessagehelper.setto (to); Mimemessagehelper.addattachment ("Hello.jpg", New Filesystemresource ("The New File" ("C:/users/administrator/desktop/icon .
JPG "));
Javamailsenderimpl.setjavamailproperties (prop);
Javamailsenderimpl.send (MimeMessage);
SYSTEM.OUT.PRINTLN ("Send message OK ...");
}
}