send mail using python

First of all, go to your mail setting and enable SMTP service then you will get an auth string.

If you are using qqmail, you can just use the host address below. If not, you have to find it yourself.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import smtplib  
import email.mime.multipart
import email.mime.text

me = '[email protected]'
auth_string = ''

msg = email.mime.multipart.MIMEMultipart()
msg['from'] = me
msg['to'] = # receiver
msg['subject'] = # subject
content = # content
msg.attach(email.mime.text.MIMEText(content))

try:
smtpObj = smtplib.SMTP_SSL("smtp.qq.com", 465)
smtpObj.connect('smtp.qq.com', 465)
smtpObj.login(me, auth_string)
smtpObj.sendmail(msg['from'], msg['to'], msg.as_string())
print("YES!")
except smtplib.SMTPException:
print("No...")