Try to write a script to send e-mail but failed

Source: Internet
Author: User
Tags python send email

#-*-coding:utf-8-*-

‘‘‘
Use Python to send mail
But not successful, after running, wait a while, return [Errno 10060] A connection attempt failed because the connected party does not properly respond after A Period of time, or established connection failed because connected host have failed to respond
Email Send fail
‘‘‘

Import Smtplib
From Email.mime.text import Mimetext


Host= ' smtp.163.com '
Port=25
timeout= ' 30 '
User= ' m17606719860 '
Usera= ' [email protected] '
prefix= ' 163.com '
Password= ' cc1842 '
to_list=[' [email protected]
content= ' python send email test '
sub= ' Hello,world '


def sendmail (to_list,sub,content):
Me= ' Hello ' + ' < ' +user+ ' @ ' +prefix+ ' > '
Msg=mimetext (content,_subtype= ' plain ', _charset= ' gb2312 ')
msg[' Subject ']= Sub
msg[' from ']=me
msg[' to ']= ', '. Join (To_list)
Try
Smtp=smtplib. SMTP ()
Smtp.set_debuglevel (1)
Smtp.connect (Host,port)
Smtp.login (User,password)
Smtp.sendmail (me,to_list,msg.as_string ())
Smtp.quit ()
print ' Email send success '
Except Exception,e:
Print E
print ' Email send fail '


If __name__== ' __main__ ': SendMail (to_list,sub,content)

Try to write a script to send e-mail but failed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.