java實現qq郵箱啟用註冊功能

來源:互聯網
上載者:User

標籤:oca   相關   設定   charset   rda   href   util   ted   pac   

1先去qq郵箱設定中開啟 POP3和STMP 服務, 記住授權碼

 

然後編寫代碼

package cn.yunhe.utils;import javax.mail.*;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage;import java.util.Properties;/** * 郵件發送工具類 * Created by Administrator on 2017/8/4. */public class MailUtils {    /**     * 發送郵件的方法     * @param to   :收件者     * @param code :啟用碼     */    public static void sendMail(String to,String code){        //1.獲得Session對象        Properties props=new Properties();        props.put("mail.transport.protocol","smtp");//連線協定        props.put("mail.smtp.host","smtp.qq.com");//主機名稱        props.put("mail.smtp.port","465");//連接埠號碼        props.put("mail.smtp.auth","true");        props.put("mail.smtp.ssl.enable","true");//設定是否使用ssl安全連線,一般都使用        props.put("mail.debug","true");//設定是否顯示debug資訊 true會在控制台顯示相關資訊        //得到回話對象        Session session=Session.getInstance(props);        //擷取郵件對象        Message message=new MimeMessage(session);        try {            //設定寄件者地址            message.setFrom(new InternetAddress("[email protected]"));            //設定收件者地址 (將參數傳進來)            message.setRecipients(Message.RecipientType.TO,new InternetAddress[]{new InternetAddress(to)});            //設定郵件標題            message.setSubject("來自購物天堂的官方啟用郵件");            //設定郵件內文            message.setContent("<h1>購物天堂官方啟用郵件!點下邊的連結完成啟用操作!</h1><h3><a href=‘http://172.16.23.150:8080/user/active?code="+code+"‘>http://172.16.23.150:8080/active?code="+code+"</a></h3>","text/html;charset=UTF-8");            //得到郵差對象            Transport transport=session.getTransport();            //串連自己的郵箱賬戶            transport.connect("[email protected]","xvqeeiaszzvubhgg");//密碼為授權碼            //發送郵件            transport.sendMessage(message,message.getAllRecipients());        } catch (MessagingException e) {            e.printStackTrace();        }//本機伺服器        /*props.setProperty("mail.host","localhost");*/       /* Session session=Session.getInstance(props, new Authenticator() {            @Override            protected PasswordAuthentication getPasswordAuthentication() {                return  new PasswordAuthentication("[email protected]","111");            }        });*/        //2.建立一個代表郵件的對象Message        /*Message message=new MimeMessage(session);        try {            //設定寄件者            message.setFrom(new InternetAddress("[email protected]"));            //設定收件者            message.setRecipient(Message.RecipientType.TO,new InternetAddress(to));//抄送 CC  密送 BCC            //設定標題            message.setSubject("來自購物天堂的官方啟用郵件");            //設定郵件內文            message.setContent("<h1>購物天堂官方啟用郵件!點下邊的連結完成啟用操作!</h1><h3><a href=‘http://172.16.23.150:8080/user/active?code="+code+"‘>http://172.16.23.150:8080/active?code="+code+"</a></h3>","text/html;charset=UTF-8");        //3.發送郵件Transport        Transport.send(message);        } catch (MessagingException e) {            e.printStackTrace();        }*/    }}

 

java實現qq郵箱啟用註冊功能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.