zoukankan      html  css  js  c++  java
  • JavaMail Demo

    package com.apptest.test;
    
    import java.util.Properties;
    
    import javax.mail.Authenticator;
    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;
    
    public class JavaMailDemo {
    
    	public static void main(String[] args) throws AddressException, MessagingException {
    		Properties props = new Properties();
    		props.setProperty("mail.host", "smtp.163.com");
    		props.setProperty("mail.smtp.auth", "true");
    		
    		Authenticator authenticator = new Authenticator() {
    			@Override
    			protected PasswordAuthentication getPasswordAuthentication() {
    				return new PasswordAuthentication("lvingw", "xxxxxxxxx");
    			}
    		};
    		Session session = Session.getInstance(props, authenticator);
    		
    		MimeMessage msg = new MimeMessage(session);
    		msg.setFrom(new InternetAddress("lvingw@163.com"));
    		msg.setRecipients(RecipientType.TO, "975753874@qq.com");
    		msg.addRecipients(RecipientType.CC, "xxxx@gmail.com");
    		
    		msg.setContent("哈哈,javaMail send mail is OK????","text/html;charset=utf8");
    		
    		Transport.send(msg);
    	}
    }
    

      

  • 相关阅读:
    Making a CocoaPod
    关于Http
    The podfile
    iOS 8个实用小技巧(总有你不知道的和你会用到的)
    关于深拷贝浅拷贝
    适配ios10(iTunes找不到构建版本)
    iOS 10 推送的简单使用
    __block 和 __weak的区别
    Masonry使用注意事项
    iOS数字键盘自定义按键
  • 原文地址:https://www.cnblogs.com/luowen/p/4348552.html
Copyright © 2011-2022 走看看