qq发送邮件

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class Mail  extends Thread  {

public static void main(String[] args) {
for(int i=0;i<1;i++){
Mail MyThread2 = new Mail();
          MyThread2.start();
}
}




public void run () { 
for(int i=0;i<4;i++){
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.qq.com");
        props.put("mail.smtp.port", "587");//使用465或587端口
        props.put("mail.smtp.auth", "true");//设置使用验证
        props.put("mail.smtp.starttls.enable","true");//使用 STARTTLS安全连接
        try {//pgxsenybqngtjbgj   tfeksjgpyafucecf
            PopupAuthenticator auth = new PopupAuthenticator();
            Session session = Session.getInstance(props, auth);
            //session.setDebug(true);//打印Debug信息
            MimeMessage message = new MimeMessage(session);
            Address addressFrom = new InternetAddress(PopupAuthenticator.mailuser + "@qq.com", "");//第一个参数为发送方电子邮箱地址;第二个参数为发送方邮箱地址的标签
            Address addressTo = new InternetAddress("11111111111@qq.com", "");//第一个参数为接收方电子邮箱地址;第二个参数为接收方邮箱地址的标签
            message.setSubject("轰炸");
            message.setText("春节大概放两个星期!!!!!!!!!!!!!");
            message.setFrom(addressFrom);
            message.addRecipient(Message.RecipientType.TO, addressTo);
            message.saveChanges();
            Transport transport = session.getTransport("smtp");
            transport.connect("smtp.qq.com", PopupAuthenticator.mailuser, PopupAuthenticator.password);
            transport.send(message);
            transport.close();
            System.out.println("发送成功"+i);
        } catch (Exception e) {
            System.out.println(e.toString());
            System.out.println("发送失败");
        }
    }
}
class PopupAuthenticator extends Authenticator {
    public static final String mailuser = "222222222";//发送方邮箱'@'符号前的内容:2222222222@qq.com
    public static final String password = "ffffiatvinnvcaec";//成功开启IMAP/SMTP服务,在第三方客户端登录时,腾讯提供的密码。注意不是邮箱密码


    public PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(mailuser, password);
    }
}


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值