python - 通过python脚本更改发件人邮件ID的显示名称
问题描述
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)
即使代码已成功执行,我在 abcd@gmail.com 中没有将显示名称显示为“随机用户”
可能是什么问题?
解决方案
您不想更改from
in smtp.sendmail()
,但您想更改电子邮件内容本身。
msg = 'From: Random User <abc@gmail.com>\nTo: abcd@gmail.com\nSubject: subject\n\nbody'
smtp.sendmail('abc@gmail.com','abcd@gmail.com', msg)
推荐阅读
- javascript - Download video embedded in html video tag using javascript
- r - How to remove a column and increase count of rows based on the value of the columns
- java - RetryPolicy does not work with coroutines
- python - 使用 Python OpenCV 在两行之间查找文本
- php - Laravel 数据库,我应该使用什么数据类型来存储护照号码?
- javascript - 如何在 JavaScript 中访问对象内所有嵌套对象的所有函数?
- java - Spring Boot Rabbitmq AMQP & WebSocket NULL 指针异常
- django - Why drf add underlines to serialized dictfield?
- python - Find list of id's which have another column change values multiple times
- azure - Azure 备份需要端口?