#!/usr/bin/python
# coding: utf-8
import smtplib
from email.mime.text import mimetext
receivers_list=["[email protected]",]
#mail_host="dns.com"
mail_host="1.2.3.4"
sender_email="[email protected]"
#mail_pwd="*************" //有的需要,有的不需要
def send_email(subject, content, receivers_list):
print 'setting mimetext'
msg = mimetext(content.encode('utf8'), _subtype = 'html', _charset = 'utf8')
msg['from'] = sender_email
msg['subject'] = u'%s' % subject
msg['to'] = ",".join(receivers_list)
try:
# s = smtplib.smtp_ssl(mail_host, 465) //有的需要,有的不需要
s = smtplib.smtp(mail_host, 25)
# s.connect(mail_host) //和上面的連線任選一種
#s.set_debuglevel(1)
#s.ehlo() //有的需要,有的不需要
#s.starttls() //有的需要,有的不需要
#s.ehlo()
#s.login(mail_user, mail_pwd) //有的需要,有的不需要
s.sendmail(sender_email, receivers_list, msg.as_string())
print 'close the connection between the mail server'
s.close()
except exception as e:
print 'exception: ', e
if __name__ == '__main__':
send_email("subject title", 'email content', receivers_list)
PYTHON傳送郵件時,有的伺服器不用密碼認證的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 usr bin python coding utf 8 importsmtpl...
html傳送郵件 Python傳送郵件(三十)
簡單郵件傳輸協議 smtp 是一種協議,用於在郵件伺服器之間傳送電子郵件和路由電子郵件。python提供smtplib模組,該模組定義了乙個smtp客戶端會話物件,可用於使用smtp或esmtp偵聽器守護程式向任何網際網路機器傳送郵件。這是乙個簡單的語法,用來建立乙個smtp物件,稍後將演示如何用它...
python 傳送郵件
coding utf 8 import smtplib from email.mime.text import mimetext from email.header import header 檔案形式的郵件 def email file mail host smtp.qq.com 郵箱伺服器 ma...