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