收到空白电子邮件,但发送的邮件很好

时间:2020-02-03 21:22:02

标签: python mimemultipart

所以直到昨天,一切正常,当我以前运行以下脚本时,它可以正常运行,并且可以正常发送电子邮件,但是现在突然运行时,电子邮件已发送出去但是收到后绝对是空白。身体什么都没有,请帮忙! 为了安全起见,我已将我的凭据替换为随机的电子邮件和密码。

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib

def process():
    SendEmail(email="abc@def.com", password="1234")


def SendEmail (email,password):

    sender_email="abc@def.com"
    receiver_email = "xyz@def.com"

    message="Hey"

    msg=MIMEMultipart('alternative')
    msg['Subject'] = "Test"
    msg['From'] = sender_email
    msg['To'] = receiver_email

    html=message

    part=MIMEText(html, 'text')
    msg.attach(part)

    obj = smtplib.SMTP('smtp.office365.com', 587)
    obj.ehlo()
    obj.starttls()
    obj.login(email, password)
    obj.sendmail(sender_email, receiver_email, msg.as_string())
    obj.quit()
    print('message')
    print('email sent')
    return

process()

0 个答案:

没有答案