Send messages to a mailbox in Python

Source: Internet
Author: User
Tags mail account

#!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.