Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发现有个地方有问题 #1

Open
361way opened this issue Sep 27, 2016 · 3 comments
Open

发现有个地方有问题 #1

361way opened this issue Sep 27, 2016 · 3 comments

Comments

@361way
Copy link

361way commented Sep 27, 2016

postmail.py文件中line 113--115行的部分,是不是写的有问题?
mail['To'] = ", ".join(receiver)
mail['Cc'] = ", ".join(cc)
mail['Bcc'] = ", ".join(bcc)
正确的写法应该是(逗号换成分号):
mail['To'] = "; ".join(receiver)
mail['Cc'] = "; ".join(cc)
mail['Bcc'] = "; ".join(bcc)

@Yinzo
Copy link
Owner

Yinzo commented Sep 27, 2016

@361way :D 这里用逗号还是分号,两种情况我都测试过,似乎是没有什么影响的,不知有没有准确的说法指出应该使用分号呢:D

@361way
Copy link
Author

361way commented Sep 27, 2016

这个倒没有,因为传多个receiver接收者的时候,发现只有第一个用户可以收到,感觉很奇怪 。receiver传的类型是list,看了下代码,没发现有问题。在测试不基于flask,直接按如下代码运行程序,多个接收者完全没问题。感觉很是奇怪,不知道你测试的时候有没这个问题(测试环境centos6.7 python2.6 flask通过easy_install安装的)

import smtplib
from email.mime.text import MIMEText
mailto_list=["[email protected]"]
mail_host="smtp.XXX.com" #设置服务器
mail_user="XXX" #用户名
mail_pass="XXXX" #口令
mail_postfix="XXX.com" #发件箱的后缀
def send_mail(to_list,sub,content): #to_list:收件人;sub:主题;content:邮件内容
me="hello"+"<"+mail_user+"@"+mail_postfix+">" #这里的hello可以任意设置,收到信后,将按照设置显示
msg = MIMEText(content,_subtype='html',_charset='gb2312') #创建一个实例,这里设置为html格式邮件
msg['Subject'] = sub #设置主题
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
s = smtplib.SMTP()
s.connect(mail_host) #连接smtp服务器
s.login(mail_user,mail_pass) #登陆服务器
s.sendmail(me, to_list, msg.as_string()) #发送邮件
s.close()
return True
except Exception, e:
print str(e)
return False
if name == 'main':
if send_mail(mailto_list,"hello","运维之路"):
print "发送成功"
else:
print "发送失败"

@Yinzo
Copy link
Owner

Yinzo commented Sep 28, 2016

我测试了下,用smtp抄送(cc) 现在似乎无效了,被抄送的邮箱都收不到邮件。但是若果作为多个接收者,即receiver是一个list的话,倒是没有问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants