Automatic email sending-, email sending-

Source: Internet
Author: User

Automatic email sending-, email sending-

# Coding = UTF-8
Created on
@ Auther: Qigege
Project: Send email Test

Import smtplib
From email. mime. text import MIMEText

# SMTP Server
Mail_host = 'smtp'
Mail_user = '******* @'
# Netease mail is a webpage version and requires a client password. Enter the webpage version mailbox to set an authorization code, that is, the client password.
Mail_password = '******'

# Sender's email
Sender = '****** @'
# Recipient's email
Receiver = ['******* @', '******* @']

Content = u'mailbox test... # content
Title = 'python SMTP Mail test' # topic
Message = MIMEText (content, 'plain ', 'utf-8 ')
# Email sender address
# Format (), {}=%, for example, '{1}, {0}, {1 }'. format ('abc', 12) --> '12, abc, 12'
Message ['from'] = '{}'. format (sender)
# Email recipient address, string list ['Accept address 1', 'Accept address 2',...] Or 'Accept address'
Message ['to'] = ','. join (Explorer) # type (message ['to']) is str
Message ['subobject'] = title

# Enable SSL. Generally, the port is 465.
SmtpObj = smtplib. SMTP_SSL (mail_host, 465)
# Logon Verification
SmtpObj. login (mail_user, mail_password)
# Send
SmtpObj. sendmail (sender, receiver, message. as_string ())
# As_string () convert the MIMEText or MIMEMultipart object to str
Print 'mail has been send successfully .'
Failed t smtplib. SMTPException as e:
Print e

Related Article

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: 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.