#!/usr/bin/env python#-*-coding:utf-8-*-#import Smtplib and MimetextImportSmtplib fromEmail. MimetextImportmimetextmail_to="[email protected]"#who to send todefSend_mail (to_list,sub,content):#set the server, user name, password, and suffix of the mailboxmail_host="smtp.163.com"Mail_user="your e-mail account number"Mail_pass="your password."Mail_postfix="163.com"Me=mail_user+"<"+mail_user+"@"+mail_postfix+">"msg=mimetext (content) msg['Subject'] =Sub msg[' from'] =Me msg[' to'] =to_listPrintmsgTry: S=Smtplib. SMTP () s.connect (mail_host) s.login (Mail_user,mail_pass) S.sendmail (Me, To_list, msg.as_string ()) S.close ()Print '1' returnTrueexceptException, E:Print '2' PrintStr (e)returnFalse#if __name__ = = ' __main__ ':if __name__=='__main__': ifSend_mail (Mail_to,"Hello","This is Python sent"): Print "sent successfully" Else: Print "Send failed"
Can be used, but to prevent your mailbox from being returned, or as spam, to be sent every once in a while.
Send messages to a mailbox in Python