中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Java郵箱自動發(fā)送郵件

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

Android開發(fā)中,當忘記密碼需要找回密碼的時候,很多情況都是向注冊郵箱自動發(fā)送注冊登錄密碼,自己寫的一個自動發(fā)送郵件的java類,親測可用。

直接貼代碼:

    public class SendMail {  
      
        static int port = 25;//端口號  
        static String server = "smtp.163.com";// 郵件服務(wù)器mail.cpip.net.cn  
        static String from = "小明";// 發(fā)送者,顯示的發(fā)件人名字  
        static String user = "xxxxx@163.com";// 發(fā)送者郵箱地址  
        static String password = "xxxxxx";// 密碼  
      
        public static void sendEmail(String email, String subject, String body)  
                throws UnsupportedEncodingException {  
            try {  
                Properties props = new Properties();  
                props.put("mail.smtp.host", server);  
                props.put("mail.smtp.port", String.valueOf(port));  
                props.put("mail.smtp.auth", "true");  
                Transport transport = null;  
                Session session = Session.getDefaultInstance(props, null);  
                transport = session.getTransport("smtp");  
                transport.connect(server, user, password);  
                MimeMessage msg = new MimeMessage(session);  
                msg.setSentDate(new Date());  
                InternetAddress fromAddress = new InternetAddress(user, from,  
                        "UTF-8");  
                msg.setFrom(fromAddress);  
                InternetAddress[] toAddress = new InternetAddress[1];  
                toAddress[0] = new InternetAddress(email);  
                msg.setRecipients(Message.RecipientType.TO, toAddress);  
                msg.setSubject(subject, "UTF-8");  
                msg.setText(body, "UTF-8");  
                msg.saveChanges();  
                transport.sendMessage(msg, msg.getAllRecipients());  
            } catch (NoSuchProviderException e) {  
                e.printStackTrace();  
            } catch (MessagingException e) {  
                e.printStackTrace();  
            }  
        }  
    }  

標簽: 代碼 服務(wù)器

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:Python實現(xiàn)http文件下載

下一篇:java讀取文件大小