A simple way to send emails in Python

A simple way to send emails in Python

# send mail

# -*- coding: UTF-8 -*-

import smtplib
from email.mime.text import MIMEText
from email.header import Header

def sendEmail(smtpServer, sendAddr, recvAddr, muser, mpass, sendSub, sendMsg):
	msg = MIMEText(sendMsg, 'plain', 'utf-8')
	msg['From'] = Header(sendAddr, 'utf-8')
	msg['To'] =  Header(recvAddr, 'utf-8')
	msg['Subject'] = Header(sendSub, 'utf-8')

		smtpObj = smtplib.SMTP() 
		smtpObj.connect(smtpServer, 25)
		smtpObj.login(muser, mpass)  
		smtpObj.sendmail(sendAddr, recvAddr, msg.as_string())
		return True
	except smtplib.SMTPException:
		return False

sendEmail("smtp.qq.com", "[email protected]", ['[email protected]'], "user1", "password1", "email-test!", "Hello email test !")	


Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example