通过python scrip更改发件人邮件id的显示名称

2024-06-06 04:00:03 发布

您现在位置:Python中文网/ 问答频道 /正文

import smtplib
import os

EMAIL_ADDRESS = abc@gmail.com
EMAIL_PASSWORD = os.environ.get('EMAIL_PASS')

with smtplib.SMTP('smtp.gmail.com',587) as smtp:
    smtp.ehlo()  #identifies ourselves with the mail server that we are using
    smtp.starttls() #to encrypt the traffic
    smtp.ehlo() #to re-identify ourselves as encrypted connection

    smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)

    subject = "Regarding your text role"
    body = "This is to inform u that ur text role has been updated"

    msg = f'Subject: {subject}\n\n{body}'

    smtp.sendmail('Random User <abc@gmail.com>','abcd@gmail.com', msg)

即使代码得到了成功执行,我也没有在中获得显示名为“Random User”abcd@gmail.com
有什么问题吗


Tags: toimportcomosaddressemailaswith