Using java to implement the mailbox group function, java implements the mailbox group Function
The examples in this article share with you the specific code for implementing mass mailing in java for your reference. The specific content is as follows:
I recently read some articles about Daniel on the Internet. I have read a good article and I will share it with you!
Below is the code
Email entity
Import java. io. serializable;/*** Mail entity class */public class Mail implements Serializable {/*** serial number */private static final long serialVersionUID =-3562218214168975242L; /*** email Encoding s */public static final String ENCODEING = "UTF-8";/*** server address */private String host; /*** server port number */private String portNumber;/*** sender's email address */private String sender;/*** recipient's email address */private String receiver; /*** sender nickname */private String name;/*** account */private String username;/*** password */private String password; /*** Topic */private String subject;/*** information (HTML supported) */private String message; public String getHost () {return host ;} public void setHost (String host) {this. host = host;} public String getSender () {return sender;} public String getPortNumber () {return portNumber;} public void setPortNumber (String portNumber) {this. portNumber = portNumber;} public void setSender (String sender) {this. sender = sender;} public String getReceiver () {return receiver;} public void setReceiver (String receiver) {this. extends ER = extends er;} public String getName () {return name;} public void setName (String name) {this. name = name;} public String getUsername () {return username;} public void setUsername (String username) {this. username = username;} public String getPassword () {return password;} public void setPassword (String password) {this. password = password;} public String getSubject () {return subject;} public void setSubject (String subject) {this. subject = subject;} public String getMessage () {return message;} public void setMessage (String message) {this. message = message ;}}
Tool
Import org. apache. commons. mail. emailException; import org. apache. commons. mail. htmlEmail; public class MailUtil {public boolean send (Mail mail) {// send email object HtmlEmail email = new HtmlEmail (); try {// here is the SMTP sending server name email. setHostName (mail. getHost (); // when the port number is not empty, the custom port number is the SMTP sending server port number if (! "". Equals (mail. getPortNumber () {email. setSSLOnConnect (true); email. setSslSmtpPort (mail. getPortNumber ();} // set email for the character set. setCharset (Mail. ENCODEING); // email address of the recipient. addTo (mail. getcycler (); // sender's email. setFrom (mail. getSender (), mail. getName (); // If you need authentication information, set authentication: User Name-password. The registration name and password email of the sender on the email server. setAuthentication (mail. getUsername (), mail. getPassword (); // The subject email to be sent. setSubject (mail. getSubject (); // the message to be sent. Because HtmlEmail is used, you can use the HTML Tag email in the mail content. setMsg (mail. getMessage (); // send an email. send (); return true;} catch (EmailException e) {e. printStackTrace (); return false ;}}}
Start
Import java. util. random; public class SimpleEmailClient {public static void main (String [] args) throws InterruptedException {Mail mail = new Mail (); mail. setHost ("smtp.qq.com"); // set the email server. If you do not need a QQ mailbox, find the relevant mail. setPortNumber ("465"); // sets the mail server port number. The default value is 25 mail. setSender ("xxxx@qq.com"); // sender mail. setName ("Yang Daxia"); // the sender's nickname is mail. setSubject ("delicious"); // send the topic mail. setMessage ("delicious"); // send mail. setUsern Ame ("xxxx@qq.com"); // login account, usually the same as the mailbox name mail. setPassword ("*********"); // when logging on to a third-party client via QQ mail, enter the "authorization code" in the password box for verification. For details about other passwords, see the description of the email server for (int I = 0; I <1000; I ++) {// Thread. sleep (2000); int max1 = 99999; int min1 = 10000; Random random = new Random (); int f = random. nextInt (max1) % (max1-min1 + 1) + min1; int max2 = 9999; int min2 = 1000; Random random2 = new Random (); int s = random2.nextInt (max2) % (max2-min2 + 1) + min2; String account = "" + f + "" + s + "@ qq.com"; mail. setcycler (account); // recipient System. out. println (account); if (new MailUtil (). send (mail) {System. out. println ("sent successfully");} else {System. out. println ("failed to send ");}}}}
The for loop is for group sending.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.