1. qq邮件群发器_工具_软件!首页
  2. 邮件群发软件

python实现的邮件自动群发脚本

很多时候我们可能需要在某种情况下自动发送邮件给对方,标准库的smtplib可以实现这个功能,代码比较简单。

#!/usr/bin/env python


import smtplib
from email.mime.text import MIMEText

#list of mail address you wana to send
to = ["xx@xx", "xx@xx"]

#user and password of your mail
MailHost = "smtp.163.com"
MailUser
= "xxxxxx"
MailPswd
= "******"
MailPostfix
= "163.com"

def SendMail(to, sub, content):

Me
= MailUser + "<" + MailUser + "@" + MailPostfix + ">"
Msg
= MIMEText(content)
Msg[
'Subject'] = sub
Msg[
'From'] = Me
Msg[
'To'] = ";".join(to)

try:
s
= smtplib.SMTP()
s.connect(MailHost)
s.login(MailUser, MailPswd)
s.sendmail(Me, to, Msg.as_string())
s.close()
return True
except Exception, e:
print str(e)
return False

def main():

sub
= "Hello"
content
= "This is a test mail"
if SendMail(to, sub, content):
print 'send successful'
else:
print 'send failed'
return 0

if __name__ == '__main__':
main()

原创文章,作者:QQ邮件群发,如若转载,请注明出处:http://www.youjianqunfa8888.com/baike/2357.html

发表评论

登录后才能评论