Java Send mail related

Source: Internet
Author: User
Tags email account

    • Send activation message
      • E-mail: A piece of space on an email server;
      • Mail server: Analogy to the Web server (tomcat), with the corresponding server software;
      • Mail protocol: Large companies send and receive servers separate, or you can use a server.
SMTP: Simple mail-sending protocol; POP3: an agreement to receive mail;
      • The whole process of sending mail: Theoretically need to be networked, but by building a local server, you can send messages locally.
      • To build a mailbox server:
        • Install the mailbox server (e-mail server, the default installation on the C drive)
        • Open the server, modify the domain name: Tools--Server settings--to customize the single domain name, for example: Shop.com.
        • Register several internal accounts: account-and new account. Password set to 55555
        • Sign up for a custom official account: Service Password: 55555
      • Install mail client software (can send mail): Avoid the web version of the session expired offline problem.
        • Popular software has: Outlook (Microsoft Charges), Foxmail (free, choose Foxmail)
        • Configuration
* Configure outgoing mail server: localhost * Configure incoming mail server: localhost
      • Encoding for mail delivery (see Mailutils.java)
    1. User activation
      • Click the activation link in the mailbox client:
        • Query based on the activation code passed in the link
                         * If user is not empty: Modify User state: 0  -->  1, the activation success message is passed to the foreground.                          * If the user is empty: The activation code fails or is tampered with, the activation failure message is passed to the foreground.  import Java.util.properties;import Javax.mail.authenticator;import Javax.mail.message;import Javax.mail.message.recipienttype;import Javax.mail.messagingexception;import javax.mail.PasswordAuthentication; Import Javax.mail.session;import Javax.mail.transport;import Javax.mail.internet.addressexception;import Javax.mail.internet.internetaddress;import javax.mail.internet.mimemessage;/** * Send Message tool class  */public class Mailutils {   /**     * ways to send messages      * @param to recipients      * @param c Ode Activation Code      */    public static void SendMail (string to, string code) {        /**         * 1. Get a Session object   &NBsp      * 2. Create an object that represents a message message         * 3. Send mail transport         */       //1. Get a Session object         Properties props = new Properties (); &nbs P       Props.setproperty ("mail.host", "localhost");//Specify who the host who sent the message is:localhost        Session session = Session.getinstance (props, New Authenticator () {            protected Pass Wordauthentication getpasswordauthentication () {                return new Passwor Dauthentication ("[email protected]", "55555");           }       );       //2. Create an object that represents a message message        Message message = new MimeMessage (session);        Try {           //2.1: Set sender       &NBSP ;     MESSAGE.SETFROM (New InternetAddress ("[email protected]"));           //2.2: Set up recipients     & nbsp      /* cc: CC, BCC:bcc*/            message.addrecipient (recipienttype.to, NE W internetaddress (To));           //2.3: Set up message title             MES Sage.setsubject ("Official Account activation Email! ");           //2.4: Set message body             message.setcontent (" &lt ;h2> welcome you xxxx, this is only Tesco official email account activation message body, do not divulge <br/> this message, so as to avoid loss to the user! Please click on the link below to complete the account activation operation.
User-activated action method:     /*** User-activated method      */      Public String Active() {          //According to the activation code to query the user:User Existuser = UserService.Findbycode(User.GetCode());          //Judgment           if (Existuser == NULL) {              //Activation code is wrong              This .Addactionmessage("Activation failed: Activation code Error!");          } Else {              //Activation successful              //Modify the status of the user              Existuser.setState(1);              Existuser.Setcode( NULL);              UserService.Update(Existuser);              This .Addactionmessage("Activation succeeded: Please login!");          }           return "MSG";     }

Java Send mail related

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.