Python implements 126 mailboxes to send mail

Use Python to send 126 emails for your reference. The specific content is as follows

Today I want to be an automated email reminder function. I just happened to be learning python recently. I said that python is so powerful. I want to try if python can get it. Search for information. It is really possible and simple and easy to understand.

from email.mail.text import MIMEText
import smtplib

# Sender list
to_list=["[email protected]","[email protected]"]
# For large mail servers, there is an anti-spam function, you must log in to send mail, such as 126,163
mail_server="smtp.126.com"   #126 mail server
mail_login_user="[email protected]" #Must be a real user, here I wrote my own 126 mailbox when testing
mail_passwd="******"    #Must be the correct password corresponding to the above user, the password corresponding to my 126 mailbox

def send_mail(to_list,sub,content):'''
 to_list:To whom
 sub:theme
 content:content
 send_mail("[email protected]","sub","content")'''
 me=mail_user+"<"+mail_user+" "
 msg =MIMEText(content)
 msg['Subject']= sub
 msg['From']= me
 msg['To']=";".join(to_list)try:
 s = smtplib.SMTP()
 s.connect(mail_host)
 s.login(mail_user,mail_pass)
 s.sendmail(me, to_list, msg.as_string())
 s.close()return True
 except Exception, e:
 print str(e)return False
if __name__ =='__main__':ifsend_mail(mailto_list,"subject","content"):
 print "Sent successfully"else:

Capture result

I'm used to capturing packets and analyzing the problems in my work. I also took a look at this. You can see that python has encapsulated the smtp protocol quite perfectly, and python can realize the mailing function with just a few lines of code.

Go to your mailbox and check it. I received the email.

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Python implements 126 mailboxes to send mail
Python implements QQ mailbox to send mail
Python uses the email module to send mail
Python implements SMTP mail sending
How Python implements the mail function
CentOS 6/7 configure sendEmail to send mail
01. Introduction to Python
Introduction to Python
How to send mail using sendemail on ubuntu
Centos 6.4 python 2.6 upgrade to 2.7
Python implements tic-tac-toe game
Centos 6.4 python 2.6 upgrade to 2.7
Python implements tic-tac-toe game
Python implements man-machine gobang
Python implements Tetris game
Python implements image stitching
Python implements minesweeper game
Python implements scanning tools
Python implements threshold regression
Python implements minesweeper games
Python implements FTP to upload files in a loop
Python implements electronic dictionary
Python implements guessing game
Centos default python2.6 upgrade to
Solution to python alignment error
Python implements simple tank battle
CentOS upgrade python2 to pyth
Python implements udp chat window
Python code to find bugs (2)
Python code to find bugs(7)
How to comment python code
Python implements WeChat airplane game
Python implements word guessing game
Python code to find bugs(4)
Python code to find bugs (3)
Python code to find bugs(9)
Python implements parking management system
Python implements digital bomb game
Python implements TCP file transfer
Python numpy implements rolling case
How to learn python quickly
How to uninstall python plugin
Introduction to Python related modules
OpenCV Python implements puzzle games
Python implements simple tic-tac-toe game
Python implements password strength verification
Python implements car management system
Python implements code block folding
Python implements panoramic image stitching
Python code to find bugs(6)
Python implements multi-dimensional array sorting
How Python implements FTP function
Python implements mean-shift clustering algorithm
Python code to find bugs (1)
Python code to find bugs(8)
3 ways to encrypt Python files
Python implements verification code recognition
How to understand python objects
Python implements gradient descent method
Python code to find bugs(5)
Python implements text version minesweeper