Send Email As…

这个希望大家不要学,但要知道伪装一个假的的发件人的email是非常容易的。

原创在这 – https://github.com/FeeiCN/Mail-Checker

# -*- coding: utf-8 -*-

"""
    fake-mail
    ~~~~~~~~~
    伪造发件人发送邮件
    :author:    Feei <[email protected]>
    :homepage:  https://github.com/FeeiCN/Mail-Checker
    :license:   GPL, see LICENSE for more details.
    :copyright: Copyright (c) 2015 Feei. All rights reserved
"""
import smtplib
import traceback
from smtplib import SMTPException
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

# change this to you own
host = 'smtp.exmail.qq.com'
port = '25'
username = '[email protected]腾讯企业邮箱自有域名.com'
password = 'aJAhWUTWbYD8SEDNdfjkdjfkdjf' # 最好开安全密码


def mail(subject, to, html, fake_name, fake_mail):
    """
    Send mail
    :param subject: 主题
    :param to: 发给谁
    :param html: 内容
    :param fake_name: 以谁的名义
    :param fake_mail: 以谁的邮箱
    :return:
    """
    msg = MIMEMultipart()
    msg['Subject'] = subject
    msg['From'] = '{0} <{1}>'.format(fake_name, fake_mail)
    # 支持多用户接收邮件
    msg['To'] = to

    text = MIMEText(html, 'html', 'utf-8')
    msg.attach(text)

    try:
        s = smtplib.SMTP(host, port)
        s.ehlo()
        s.starttls()
        s.ehlo()
        s.login(username, password)
        s.sendmail(username, to.split(','), msg.as_string())
        s.quit()
        return True
    except SMTPException:
        print('Send mail failed')
        traceback.print_exc()
        return False


assert mail('Test by @Hone', 
            '收件人@gmail.com', 
            'Fake Mail Content', 
            '马化腾', # 发件人名字
            '[email protected]' # 伪装的发件人
            )

运行

python send_mail_as.py

Leave a Reply