天學(xué)習(xí)了如何用Java[1] 發(fā)送普通郵件,HTML郵件和帶附件的郵件。黑客最喜歡干的事情就是發(fā)釣魚郵件,安全磚家還為其美名叫魚叉攻擊,嘖嘖。
ailx10:網(wǎng)絡(luò)安全優(yōu)秀回答者,網(wǎng)絡(luò)安全碩士
發(fā)送一封簡單的QQ郵件:
package hackbiji;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
public class hello {
public static void main(String[] args) {
String to="792161993@qq.com";
String from="393803933@qq.com";
String host="smtp.qq.com";
Properties properties=System.getProperties();
properties.setProperty("mail.smtp.host",host);
properties.put("mail.smtp.auth","true");
Session session=Session.getDefaultInstance(properties, new Authenticator() {
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("393803933","***********");
}
});
try {
MimeMessage mimeMessage=new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress(from));
mimeMessage.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
mimeMessage.setSubject("主題:黑客筆記");
mimeMessage.setText("正文:我是ailx10,我喜歡2進(jìn)制安全和滲透技術(shù)");
Transport.send(mimeMessage);
System.out.println("發(fā)送郵件成功");
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
發(fā)送一封HTML QQ郵件:
package hackbiji;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
public class hello {
public static void main(String[] args) {
String to="792161993@qq.com";
String from="393803933@qq.com";
String host="smtp.qq.com";
Properties properties=System.getProperties();
properties.setProperty("mail.smtp.host",host);
properties.put("mail.smtp.auth","true");
Session session=Session.getDefaultInstance(properties, new Authenticator() {
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("393803933@qq.com","************");
}
});
try {
MimeMessage mimeMessage=new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress(from));
mimeMessage.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
mimeMessage.setSubject("主題:黑客筆記");
mimeMessage.setContent("<img src=\"http://hackbiji.top/images/avatar.jpg\" width=\"50\" height=\"50\" />","text/html");
Transport.send(mimeMessage);
System.out.println("發(fā)送郵件成功");
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
發(fā)送一封帶附件的QQ郵件
package hackbiji;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.util.Properties;
public class hello {
public static void main(String[] args) {
String to="792161993@qq.com";
String from="393803933@qq.com";
String host="smtp.qq.com";
Properties properties=System.getProperties();
properties.setProperty("mail.smtp.host",host);
properties.put("mail.smtp.auth","true");
Session session=Session.getDefaultInstance(properties, new Authenticator() {
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("393803933@qq.com","***********");
}
});
try {
MimeMessage mimeMessage=new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress(from));
mimeMessage.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
mimeMessage.setSubject("主題:黑客筆記");
MimeBodyPart msgBodyPart=new MimeBodyPart();
msgBodyPart.setText("正文:我是ailx10");
MimeMultipart mimeMultipart=new MimeMultipart();
mimeMultipart.addBodyPart(msgBodyPart);
msgBodyPart=new MimeBodyPart();
String filepath="C:\\Users\\Admin\\IdeaProjects\\helloworld\\src\\src\\main\\java\\hackbiji\\hack.zip";
String filename="hack.zip";
FileDataSource fileDataSource=new FileDataSource(filepath);
msgBodyPart.setDataHandler(new DataHandler(fileDataSource));
msgBodyPart.setFileName(filename);
mimeMultipart.addBodyPart(msgBodyPart);
mimeMessage.setContent(mimeMultipart);
Transport.send(mimeMessage);
System.out.println("發(fā)送郵件成功");
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
Python中,可以使用smtplib庫和email庫來發(fā)送郵件。以下是一個基本的示例,展示如何使用這些庫來發(fā)送一封簡單的郵件。
smtplib和email是Python的標(biāo)準(zhǔn)庫,通常不需要單獨(dú)安裝。但是,如果你使用的是一個精簡的Python環(huán)境,可能需要確保這些庫是可用的。
Python
1import smtplib
2from email.mime.text import MIMEText
3from email.header import Header
4
5# 發(fā)件人郵箱
6sender='your_email@example.com'
7# 收件人郵箱
8receiver='receiver_email@example.com'
9# 發(fā)送郵件的SMTP服務(wù)器
10smtp_server='smtp.example.com'
11# 發(fā)件人的郵箱密碼或授權(quán)碼
12password='your_password'
13
14# 郵件內(nèi)容
15mail_content='這是郵件的正文內(nèi)容。'
16# 郵件主題
17mail_subject='郵件的主題'
18
19# 創(chuàng)建一個MIMEText對象
20message=MIMEText(mail_content, 'plain', 'utf-8')
21message['From']=Header("發(fā)件人名稱", 'utf-8')
22message['To']=Header("收件人名稱", 'utf-8')
23message['Subject']=Header(mail_subject, 'utf-8')
24
25try:
26 # 連接SMTP服務(wù)器
27 smtpObj=smtplib.SMTP(smtp_server, 587)
28 # 開啟TLS加密(某些服務(wù)器需要)
29 smtpObj.starttls()
30 # 登錄SMTP服務(wù)器
31 smtpObj.login(sender, password)
32 # 發(fā)送郵件
33 smtpObj.sendmail(sender, receiver, message.as_string())
34 print("郵件發(fā)送成功!")
35except smtplib.SMTPException as e:
36 print("Error: 無法發(fā)送郵件,錯誤信息:", e)
37finally:
38 # 關(guān)閉連接
39 smtpObj.quit()
通過調(diào)整上述代碼中的SMTP服務(wù)器、端口、用戶名、密碼以及郵件內(nèi)容和接收者,你可以根據(jù)自己的需求發(fā)送郵件。
到一個比較有意思的網(wǎng)站,資源不少,在富文本框中直接復(fù)制了html,現(xiàn)在想把這些html中的附件下載到自己的服務(wù)器上,首先需要分析一下html把這些軟件的src找出來
// <summary>
/// 獲取字符串中SRC集合
/// </summary>
/// <param name="content">字符串</param>
/// <returns></returns>
public List<string> GetALLSRC(string content)
{
Regex rg=new Regex("src=\"([^\"]+)\"", RegexOptions.IgnoreCase);
var img=rg.Match(content);
List<string> imgUrl=new List<string>();
while (img.Success)
{
imgUrl.Add(img.Groups[1].Value);
img=img.NextMatch();
}
return imgUrl;
}
*請認(rèn)真填寫需求信息,我們會在24小時內(nèi)與您取得聯(lián)系。