激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

腳本之家,腳本語(yǔ)言編程技術(shù)及教程分享平臺(tái)!
分類(lèi)導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - Python django實(shí)現(xiàn)簡(jiǎn)單的郵件系統(tǒng)發(fā)送郵件功能

Python django實(shí)現(xiàn)簡(jiǎn)單的郵件系統(tǒng)發(fā)送郵件功能

2020-11-26 00:28鄰家大叔HOME Python

這篇文章主要介紹了Python django實(shí)現(xiàn)簡(jiǎn)單的郵件系統(tǒng)發(fā)送郵件功能,結(jié)合實(shí)例形式分析了django發(fā)送郵件的實(shí)現(xiàn)技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了Python django實(shí)現(xiàn)簡(jiǎn)單的郵件系統(tǒng)發(fā)送郵件功能。分享給大家供大家參考,具體如下:

django郵件系統(tǒng)

Django發(fā)送郵件官方中文文檔

總結(jié)如下:

1、首先這份文檔看三兩遍是不行的,很多東西再看一遍就通順了。
2、send_mail()、send_mass_mail()都是對(duì)EmailMessage類(lèi)使用方式的一個(gè)輕度封裝,所以要關(guān)注底層的EmailMessage。
3、異常處理防止郵件頭注入。
4、一定要弄懂Email backends 郵件發(fā)送后端
5、多線程的郵件發(fā)送。

個(gè)人簡(jiǎn)單配置如下:

首先是settings.py文件

?
1
2
3
4
5
6
7
8
9
10
#settings.py
#郵件配置
EMAIL_HOST = 'smtp.gmail.com'          #SMTP地址
EMAIL_PORT = 25                 #SMTP端口
EMAIL_HOST_USER = '[email protected]'    #我自己的郵箱
EMAIL_HOST_PASSWORD = '******'         #我的郵箱密碼
EMAIL_SUBJECT_PREFIX = u'[CoorCar網(wǎng)]'      #為郵件Subject-line前綴,默認(rèn)是'[django]'
EMAIL_USE_TLS = True               #與SMTP服務(wù)器通信時(shí),是否啟動(dòng)TLS鏈接(安全鏈接)。默認(rèn)是false
#管理員站點(diǎn)
SERVER_EMAIL = '[email protected]'      #The email address that error messages come from, such as those sent to ADMINS and MANAGERS.

這里推薦:各大型郵箱smtp服務(wù)器及端口收集

各大型郵箱smtp服務(wù)器及端口收集:

新浪郵箱smtp服務(wù)器
外發(fā)服務(wù)器:smtp.vip.sina.com
收件服務(wù)器:pop3.vip.sina.com
新浪免費(fèi)郵件
外發(fā)服務(wù)器:smtp.sina.com.cn
收件服務(wù)器:pop3.sina.com.cn
163郵箱smtp服務(wù)器
pop: pop.163.com
smtp: smtp.163.com
QQ郵箱smtp服務(wù)器及端口
接收郵件服務(wù)器:imap.exmail.qq.com,使用SSL,端口號(hào)993
發(fā)送郵件服務(wù)器:smtp.exmail.qq.com,使用SSL,端口號(hào)465或587
yahoo郵箱smtp服務(wù)器
接:pop.mail.yahoo.com.cn
發(fā):smtp.mail.yahoo.com
126郵箱smtp服務(wù)器
pop: pop.126.com
smtp: smtp.126.com
新浪免費(fèi)郵箱
POP3:pop.sina.com
SMTP:smtp.sina.com
SMTP端口號(hào):25
新浪VIP郵箱
POP3:pop3.vip.sina.com
SMTP:smtp.vip.sina.com
SMTP端口號(hào):25
新浪企業(yè)郵箱
POP3:pop.sina.com
SMTP:smtp.sina.com
SMTP端口號(hào):25
雅虎郵箱
POP3:pop.mail.yahoo.cn
SMTP:smtp.mail.yahoo.cn
SMTP端口號(hào):25
搜狐郵箱
POP3:pop3.sohu.com
SMTP:smtp.sohu.com
SMTP端口號(hào):25
TOM郵箱
POP3:pop.tom.com
SMTP:smtp.tom.com
SMTP端口號(hào):25
Gmail郵箱
POP3:pop.gmail.com
SMTP:smtp.gmail.com
SMTP端口號(hào):587 或 25
QQ郵箱
POP3:pop.exmail.qq.com
SMTP:smtp.exmail.qq.com
SMTP端口號(hào):25
263郵箱
域名:263.net
POP3:263.net
SMTP:smtp.263.net
SMTP端口號(hào):25
域名:x263.net
POP3:pop.x263.net
SMTP:smtp.x263.net
SMTP端口號(hào):25
域名:263.net.cn
POP3:263.net.cn
SMTP:263.net.cn
SMTP端口號(hào):25
域名:炫我型
POP3:pop.263xmail.com
SMTP:smtp.263xmail.com
SMTP端口號(hào):25
21CN 免費(fèi)郵箱
POP3:pop.21cn.com
SMTP:smtp.21cn.com
IMAP:imap.21cn.com
SMTP端口號(hào):25
21CN 經(jīng)濟(jì)郵郵箱
POP3:pop.21cn.com
SMTP:smtp.21cn.com
SMTP端口號(hào):25
21CN 商務(wù)郵郵箱
POP3:pop.21cn.net
SMTP:smtp.21cn.net
SMTP端口號(hào):25
21CN 快感郵箱
POP3:vip.21cn.com
SMTP:vip.21cn.com
SMTP端口號(hào):25
21CN Y郵箱
POP3:pop.y.vip.21cn.com
SMTP:smtp.y.vip.21cn.com
SMTP端口號(hào):25
中華網(wǎng)任我郵郵箱
POP3:rwpop.china.com
SMTP:rwsmtp.china.com
SMTP端口號(hào):25
中華網(wǎng)時(shí)尚、商務(wù)郵箱
POP3:pop.china.com
SMTP:smtp.china.com
SMTP端口號(hào):25

那么發(fā)送郵件如下:

?
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
def setEmail(request):
  if request.method == "POST":
#    方式一:
#     send_mail('subject', 'this is the message of email', '[email protected]', ['[email protected]','[email protected]'], fail_silently=True)
#    方式二:
#     message1 = ('subject1','this is the message of email1','[email protected]',['[email protected]','[email protected]'])
#     message2 = ('subject2','this is the message of email2','[email protected]',['[email protected]','[email protected]'])
#     send_mass_mail((message1,message2), fail_silently=False)
#    方式三:防止郵件頭注入
#     try:
#       send_mail(subject, message, from_email, recipient_list, fail_silently, auth_user, auth_password, connection)
#     except BadHeaderError:
#       return HttpResponse('Invaild header fount.')
#    方式四:EmailMessage()
    #首先實(shí)例化一個(gè)EmailMessage()對(duì)象
#     em = EmailMessage('subject','body','[email protected]',['[email protected]'],['[email protected]'],header={'Reply-to':'[email protected]'})
    #調(diào)用相應(yīng)的方法
#     方式五:發(fā)送多用途郵件
    subject,form_email,to = 'hello','[email protected]','[email protected]'
    text_content = 'This is an important message'
    html_content = u'<b>激活鏈接:</b><a href="http://www.baidu.com" rel="external nofollow" >http:www.baidu.com</a>'
    msg = EmailMultiAlternatives(subject,text_content,form_email,[to])
    msg.attach_alternative(html_content, 'text/html')
    msg.send()
#    發(fā)送郵件成功了給管理員發(fā)送一個(gè)反饋
#     mail_admins(u'用戶注冊(cè)反饋', u'當(dāng)前XX用戶注冊(cè)了該網(wǎng)站', fail_silently=True)
    return HttpResponse(u'發(fā)送郵件成功')
  return render_to_response('common/test.html')

截圖如下:

Python django實(shí)現(xiàn)簡(jiǎn)單的郵件系統(tǒng)發(fā)送郵件功能

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Send_mail(object):
  '''發(fā)送郵件'''
  def __init__(self,sender,passward,receivers):
    self.sender=sender
    self.password=passward
    self.receivers=receivers
  def send(self,ShowText,Name,Header_show):
    '''
    :param ShowText: 發(fā)送內(nèi)容
    :param Name: 發(fā)送者
    :param Header_show: 發(fā)送文件抬頭
    :return:
    '''
    message = MIMEText('%s'%(ShowText), 'plain', 'utf-8')
    message['From'] = Header("%s"%(Name), 'utf-8')
    message['To'] = Header("[email protected]")
    message['Subject'] = Header("%s"%(Header_show),'utf-8')
    smtpObj=smtplib.SMTP('smtp.163.com')
    smtpObj.set_debuglevel(1)
    smtpObj.login(self.sender,self.password)
    smtpObj.sendmail(self.sender,self.receivers,message.as_string())
    smtpObj.quit()

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美三级短视频 | 操操影视| 国产papa| 一级大片一级一大片 | 精品国产亚洲人成在线 | 国产精品99久久久久久久 | 日本爽快片100色毛片视频 | 久久久成人一区二区免费影院 | 欧美第1页 | 精国品产一区二区三区有限公司 | 少妇一级淫片免费放4p | 黄色羞羞| 亚洲综合一区二区三区 | 国产精品久久久久久影院8一贰佰 | 久久艹国产精品 | 成人在线视频精品 | 最新中文在线视频 | 色在线观看视频 | 国产一区二区三区在线免费观看 | 国产分类视频 | 美女黄影院 | 在线看免费观看日本 | 国产男女爽爽爽爽爽免费视频 | 亚洲精品午夜国产va久久成人 | 韩国美女一区 | a级欧美 | 2019天天干夜夜操 | 久久久久性视频 | 亚洲国产精品久久久久久久 | 久久国产夫妻视频 | www日韩在线 | 免费在线观看国产精品 | 国产精品亚洲欧美 | 国产精品色综合 | 深夜视频在线观看 | 在线观看国产www | 国产精品久久亚洲 | 精品中文字幕在线观看 | 欧美综合成人 | 国产一级在线看 | 久久久久久久久日本理论电影 |