最近垃圾和钓鱼邮件比较猖狂,在技术交流群里有人咨询,钓鱼邮件是从邮箱A发来的,发现该邮的回复地址确是另一个邮箱B,这个是怎么实现的。
比如:
其实很简单,构造邮件时添加一个'Reply-to'参数就可以了。
代码如下:
增加一个 message['Reply-to'] = replyto
#!/usr/bin/env python3
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import getpass
def send_email():
mail_host = 'x.x.x.x'
mail_user = 'samaccount'
mail_pwd = getpass.getpass("Password:")
sender = '[email protected]'
receive = '[email protected]'
replyto = '[email protected]'
html = '''\
<html>
<body>
<p>
<a rel="nofollow" href = "https://www.google.com/">https://www.163.com</a>
</p>
</body >
</html>
'''
message = MIMEText(html, "html")
message['subject'] = '安全通知:密码过期,请尽快更改'
message['From'] = sender
message['To'] = receive
message['Reply-to'] = replyto
smtpobj = smtplib.SMTP(mail_host, 587)
smtpobj.starttls()
smtpobj.login(mail_user,mail_pwd)
try:
smtpobj.sendmail(sender,receive,message.as_string())
print('send sucess!')
smtpobj.quit()
except smtplib.SMTPException:
print('send failure!')
if __name__ == '__main__':
send_email()
看看效果:
看看邮件源代码:
标签:__,send,地址,回复,import,smtpobj,mail,message,邮件 From: https://blog.51cto.com/magic3/6103743