Send and receive emails in python

Source: Internet
Author: User
& Quot; # coding: utf-8importsmtplibfromemail.mime.textimportMIMETextfromemail.headerimportHeadersender ××× @ 163. comreceiver ××× @ qq. comsubjectpythonemailtest2smtpser... & quot; # 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 a password

Msg = MIMEText (' ', 'text', 'utf-8') # The parameter 'utf-8' is required for Chinese characters and is not required for single-byte characters.
Msg ['subobject'] = Header (Subject, 'utf-8 ')
Msg ["To"] = worker Er
Smtp = smtplib. SMTP ()
Smtp. connect ('smtp .163.com ')
Smtp. login (username, password)
Smtp. sendmail (sender, explorer, msg. as_string ())
Smtp. quit ()
------------ If passwd is not an authorization code, the following error is returned -------------------

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 ')

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.