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 .163.com'
Mail_user = '******* @ 163.com'
# 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 = '****** @ 163.com'
# Recipient's email
Receiver = ['******* @ qq.com', '******* @ qq.com']
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
Try:
# 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