###########################
#
# 使用python发送邮件
#
###########################
import os
import smtplib
import mimetypes
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEAudio import MIMEAudio
from email.MIMEImage import MIMEImage
from email.Encoders import encode_base64
def sendMail(subject, text):
gmailUser = 'xxxx@xxx.com'
gmailPassword = ''
recipient = 'lxxxx@xxx.cn
msg = MIMEMultipart()
msg['From'] = gmailUser
msg['To'] = recipient
msg['Subject'] = subject
msg.attach(MIMEText('''<a>%s</a>''' %text, _subtype='html',_charset='UTF-8'))
mailServer = smtplib.SMTP('smtp.cnnic.cn', 25)
mailServer.ehlo()
#mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmailUser, gmailPassword)
mailServer.sendmail(gmailUser, recipient, msg.as_string())
mailServer.close()
print('Sent email to %s' % recipient)
# start to test
sendMail('你好吗?', '欢迎使用python测试邮件')
#
# 使用python发送邮件
#
###########################
import os
import smtplib
import mimetypes
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEAudio import MIMEAudio
from email.MIMEImage import MIMEImage
from email.Encoders import encode_base64
def sendMail(subject, text):
gmailUser = 'xxxx@xxx.com'
gmailPassword = ''
recipient = 'lxxxx@xxx.cn
msg = MIMEMultipart()
msg['From'] = gmailUser
msg['To'] = recipient
msg['Subject'] = subject
msg.attach(MIMEText('''<a>%s</a>''' %text, _subtype='html',_charset='UTF-8'))
mailServer = smtplib.SMTP('smtp.cnnic.cn', 25)
mailServer.ehlo()
#mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmailUser, gmailPassword)
mailServer.sendmail(gmailUser, recipient, msg.as_string())
mailServer.close()
print('Sent email to %s' % recipient)
# start to test
sendMail('你好吗?', '欢迎使用python测试邮件')