Python sends and receives emails

巴扎黑
Release: 2016-11-26 11:26:06
Original
1613 people have browsed it

#coding: utf-8
import smtplib
from email.mime.text import MIMEText
from email.header import Header

sender = '×××@163.com'
receiver = '×××@qq.com '
subject = 'python email test2'
smtpserver = 'smtp.163.com'
username = '×××'
password = '×××' # Authorization code, not password

msg = MIMEText('Hello ','text','utf-8')#Chinese requires parameter 'utf-8', single-byte characters do not need
msg['Subject'] = Header(subject, 'utf-8')
msg[" To"]=receiver
smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
------------If passwd is not an authorization code, the error will be reported as follows------------------

jack @jack-desktop:~/work/script/test$ python testemai.py
Traceback (most recent call last):
File "testemai.py", line 19, in
smtp.login(username, password )
File "/home/jack/anaconda/lib/python2.7/smtplib.py", line 622, in login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, 'Error: authentication failed')
jack@jack-desktop:~/work/script/test$ python testemai.py
Traceback (most recent call last):
File "testemai.py", line 19, in
smtp.login(username , password)
File "/home/jack/anaconda/lib/python2.7/smtplib.py", line 622, in login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, 'Error: authentication failed ')

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!