Message Delivery---Implementation

Source: Internet
Author: User
Tags auth

public class MailSender {

Static final Logger Logger = Loggerfactory.getlogger (Mailsender.class);

Public MailSender () {
}

public static void SendMessage (string guest, String AccountName, String checkval) {

Properties props = System.getproperties ();
Props.put ("Mail.smtp.host", "smtp.163.com");
Props.put ("Mail.smtp.auth", "true");

Mailauthenticator Mailauth = new Mailauthenticator ("xmkj56@163.com", "glayshx"); //...
Session session = Session.getdefaultinstance (props, Mailauth);
try {
MimeMessage msg = new MimeMessage (session);
Msg.setfrom (New InternetAddress ("xmkj56@163.com", "Shanghai Auction Industry Association"));
Msg.addrecipient (Message.recipienttype.to,new internetaddress (guest));
Msg.setsubject ("Online auction" email user Registration verification ");
Msg.setsentdate (New Date ());

Msg.settext (AccountName + "\ n" +
"This letter was sent by the Shanghai Auction Industry Association. \ n "+
"\ n" +
"----------------------------------------------------------------------\ n" +
"Account activation instructions \ n" +
"----------------------------------------------------------------------\ n" +
"You are a new user of our website and we need to verify your address validity to avoid spam or address misuse." \ n "+
"You can activate your account by clicking on the link below: \ n" +
Constants.email_send_url + "/" + Checkval + "\ n" +
"http://wangpai1.staa.com.cn/" + checkval + "\ n" +
(If this is not a link, paste the address manually into the browser's address bar and then access it) \ n "+
"Thank you for your visit, I wish you a pleasant use." \ n "+
"\ n" +
"Yours \ n" +
"\ n" +
"Shanghai Auction Industry Association management team \ n" +
"http://wangpai.staa.com.cn\n");

Msg.savechanges (); Implicit with Send ()

   transport.send (msg);
  } catch (Messagingexception Mex) {
         System.out.println ("Send failed, Exception:" + Mex);
    } catch (Unsupportedencodingexception e) {
   //TODO auto-generated Catch block
   e.printstacktrace ();
  }
 }
 
 public static void Sendpassmessage (string guest, String AccountName, String checkval) {
  
   Properties props = System.getproperties ();
  props.put ("Mail.smtp.host", "smtp.163.com");
  props.put ("Mail.smtp.auth", "true");
  
  mailauthenticator mailauth = new Mailauthenticator ("xmkj56@163.com", "glayshx");  /...
  session Session = session.getdefaultinstance (props, Mailauth);
  try {

MimeMessage msg = new MimeMessage (session);
Msg.setfrom (New InternetAddress ("xmkj56@163.com", "Shanghai Auction Industry Association"));
Msg.addrecipient (Message.recipienttype.to,new internetaddress (guest));
Msg.setsubject ("" Network Auction "email password back");
Msg.setsentdate (New Date ());

Msg.settext (AccountName + "\ n" +
"This letter was sent by the Shanghai Auction Industry Association. \ n "+
"\ n" +
"----------------------------------------------------------------------\ n" +
"Account password reset instructions \ n" +
"----------------------------------------------------------------------\ n" +
"You can do it at: \ n" +
Constants.email_send_url + "/" + "recoverpassmanage_email\n\n" +
"Use temporary password:" + checkval + "\n\n\n" +
"Thank you for your visit, I wish you a pleasant use." \ n "+
"\ n" +
"Yours \ n" +
"\ n" +
"Shanghai Auction Industry Association management team \ n" +
"http://wangpai.staa.com.cn\n");

Msg.savechanges (); Implicit with Send ()

Transport.send (msg);
} catch (Messagingexception Mex) {
System.out.println ("Send failed, Exception:" + Mex);
} catch (Unsupportedencodingexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.