2016-05-16 75 views
-1

我有一个python脚本来发送电子邮件,它工作得很好,但问题是当我检查我的电子邮件收件箱。 enter image description herePython电子邮件“从名称”定制

我想这个用户名是自定义用户名,而不是整个电子邮件地址。

enter image description here

+2

不要发布文本图像*发布实际文本*以及您尝试过的研究内容。我也删除了django标签,因为这看起来不像django如何发送消息,所以我假设它的金字塔 – Sayse

回答

1

,你应该为从地址使用的格式是:

Your Name <[email protected]> 
+0

我不明白我想通过一个字符串右边的列表? –

+0

在你的'fromaddr'变量 –

+0

谢谢你的工作 –

0

我得到这个代码在https://en.wikibooks.org/wiki/Python_Programming/Email

from email.mime.text import MIMEText 
from email.mime.multipart import MIMEMultipart 
fromaddr = "[email protected]" 
toaddr = "[email protected]" 
msg = MIMEMultipart() 
msg['From'] = fromaddr 
msg['To'] = toaddr 
msg['Subject'] = "" 
body = "This is just a test email. Do not reply to this" 
msg.attach(MIMEText(body, 'plain')) 
import smtplib 
server = smtplib.SMTP('smtp.gmail.com', 587) 
server.ehlo() 
server.starttls() 
server.ehlo() 
server.login("youremailusername", "password") 
text = msg.as_string() 
server.sendmail(fromaddr, toaddr, text) 

格式从地址为
[email protected]
地址格式为
[email protected]smtplib.SMTP接受0或2个参数。 第一个参数是类型str,第二个参数是类型int