0
点赞
收藏
分享

微信扫一扫

构造邮件回复地址

最近垃圾和钓鱼邮件比较猖狂,在技术交流群里有人咨询,钓鱼邮件是从邮箱A发来的,发现该邮的回复地址确是另一个邮箱B,这个是怎么实现的。

比如:

image.png

其实很简单,构造邮件时添加一个'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 = 'shi@xxx.com'
    receive = 'shi@xxx.com'
    replyto = 'zhenning.shi@163.com'
    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()


看看效果: image.png

看看邮件源代码:

image.png

举报

相关推荐

0 条评论