Message entity class
Public classMailImplementsSerializable { Public Static FinalString encodeing = "UTF-8"; PrivateString host;//Server Address Private intPort//Port Settings PrivateString Sender;//Sender's Mailbox PrivateString receiver;//Recipient's Mailbox PrivateString name;//Sender Nickname PrivateString username;//Account Number PrivateString password;//Password PrivateString subject;//Theme PrivateString message;//information (HTML supported)get () and set ()}
Mail Action Class
Public BooleansendMail (mail mail) {//instantiate an email object to sendHtmlemail email =NewHtmlemail (); Try { //the name of the SMTP sending server (e.g. QQ: "smtp.qq.com")Email.sethostname (Mail.gethost ()); //setting of the character encoding setEmail.setcharset (mail.encodeing); //Set PortEmail.setsmtpport (Mail.getport ()); //Recipient's Mailboxemail.addto (Mail.getreceiver ()); //Sender's MailboxEmail.setfrom (Mail.getsender (), Mail.getname ()); //If authentication is required//Set up authentication: User name-password. Is the sender's login name and password on the mail serveremail.setauthentication (Mail.getusername (), Mail.getpassword ()); //subject of the message to be sentEmail.setsubject (Mail.getsubject ()); //information to be sent, due to the use of htmlemail, the content of the message allows inserting HTML code blocksemail.setmsg (Mail.getmessage ()); //SendEmail.send (); return true; } Catch(emailexception e) {e.printstacktrace (); return false; } }
Implementing the test Management system logic one mail sending configuration via Sping3 +hibernate4+strutsmvc