今天給大家分享一個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 = "[email protected]";//自己設置
//收件人郵箱
String to = "[email protected]";//自己設置
//獲取系統屬性
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("[email protected]", "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郵箱設置的賬戶中:第一個和第四個,開啓服務。記得在代碼中用授權碼登錄,不要用自己的密碼。