SoFunction
Updated on 2024-11-21

Python implementation of a simple send mail script to share


#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Import smtplib and MIMEText
import smtplib,sys
from import MIMEText
  
def send_mail(sub,content):
    #############
#Who to send it to, here it is to 1 person
    mailto_list=["wangwei03@"]
    #####################
#Set up the server, username, password, and mailbox suffixes
    mail_host=""
    mail_user="wangwei03@"
    mail_pass="123456677890"
    mail_postfix=""
    ######################
    '''''
to_list:To whom?
sub:Subject
content:Content
    send_mail("aaa@","sub","content")
    '''
    me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
    msg = MIMEText(content,_charset='gbk')
    msg['Subject'] = sub
    msg['From'] = me
    msg['To'] = ";".join(mailto_list)
    try:
        s = ()
        (mail_host)
        (mail_user,mail_pass)
        (me, mailto_list, msg.as_string())
        ()
        return True
    except Exception, e:
        print str(e)
        return False
if __name__ == '__main__':
if send_mail(u'This is a python test mail',u'python send mail'):.
print u'Sent successfully'
    else:
print u'Failed to send'