Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1092387
  • 博文数量: 252
  • 博客积分: 4561
  • 博客等级: 上校
  • 技术积分: 2833
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-15 08:23
文章分类

全部博文(252)

文章存档

2015年(2)

2014年(1)

2013年(1)

2012年(16)

2011年(42)

2010年(67)

2009年(87)

2008年(36)

分类:

2009-06-24 10:15:51

import java.io.*;
import java.util.*;
import java.net.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.internet.MimeMultipart;

public class readline
{
        public Session CreateSession() throws Exception
        {
                Properties prop = new Properties();
                prop.setProperty("mail.transport.protocol", "smtp");
                prop.setProperty("mail.smtp.auth", "true");

                Session session = Session.getInstance(prop);
                session.setDebug(true);

                return session;
        }

        public void SendMail(Session session) throws Exception
        {
                String server = "smtp.163.com";
                String user = "ngad@163.com";
                String pass = "xxxxx";


                String from = "ngad@163.com";
                String to = "blues@gmail.com";
                String subject = "mailtest";

                for (int i = 0; i < 10; i++)
                {
                        System.out.println(i);
                        MimeMessage message = new MimeMessage(session);

                        message.setFrom(new InternetAddress(from));
                        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
                        message.setSubject(subject);

                        message.setText("test" + String.valueOf(i));

                        message.saveChanges();

                        Transport transport = session.getTransport();
                        transport.connect(server, user, pass);
                        transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
                        transport.close();
                }
        }

        public static void main(String args[]) throws Exception
        {
                readline t = new readline();

                Session session = t.CreateSession();

                t.SendMail(session);

                System.exit(0);
        }


}

阅读(459) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~