`
暗夜骑士0376
  • 浏览: 80211 次
  • 性别: Icon_minigender_1
  • 来自: 信阳
社区版块
存档分类
最新评论

JavaMails 学习(二)

阅读更多
今天是学习了向多个邮箱发送邮件的类型
了解了群发的一些概念
比如说将密码传进session 还有群发的类的使用


/**
 * 
 */
package org.wangsheng.testJavaMails;

import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *描述:进行发送多人的试验方法
 * @author 王胜
 * @date 2010-3-30 下午06:54:20
 */
public class Demo2 {

	/**
	 *描述:
	 *@param args
	 *作者:王胜
	 *日期 2010-3-30 下午06:54:20
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
        Properties props = new Properties();
        // 存储各种协议当session加入该对象后就可以进行将协议存进session中
        props.setProperty("mail.smtp.auth", "true");
        props.setProperty("mail.transport.protocal", "smtp");
        props.setProperty("mail.debug", "true");
        props.setProperty("mail.host", "smtp.sina.com");
		Session session = Session.getInstance(props,
				new Authenticator(){
			      protected PasswordAuthentication getPasswordAuthentication(){
			    	  return new PasswordAuthentication("wangsheng0376","ws1210");
			      }
		        }
		);		
		Message msg = new MimeMessage(session);
		try{
			
			msg.setFrom(new InternetAddress("wangsheng0376@sina.com"));
			msg.setSubject("中文主题");
			msg.setRecipients(Message.RecipientType.TO, 
					InternetAddress.parse("wangsheng0376@sina.com,wangsheng@sohu.com"));
		    msg.setContent("<span>hehe</span>",
		    		"text/html;charset=gbk");
			Transport.send(msg);
		    
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
	}

}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics