# smtp服務的郵箱伺服器
email_host = 'smtp.163.com'
# smtp服務固定的端⼝是25
email_port = 25
#傳送郵件的郵箱
email_host_user = '[email protected]'
#在郵箱中設定的客戶端授權密碼
email_host_password = 'q123456'
#收件⼈看到的發件⼈ 《此處要和傳送郵件的郵箱相同》
email_from = 'python'
#⼀封郵件
from django.core.mail import send_mail
from django.conf import settings
def sendone(request):
send_mail('標題', '內容', settings.email_from,
['[email protected]'])
return httpresponse("發⼀封郵件")
# 發多封郵件
def sendone(request):
message1 = ('subject here', 'here is the message',
settings.email_from, ['[email protected]'])
message2 = ('subject here', 'here is the message',
settings.email_from, ['[email protected]'])
send_mass_mail((message1,message2), fail_silently=false)
return httpresponse('傳送多封郵件')
#渲染模板進⾏郵件傳送
def sendone(request):
subject, from_email, to = 'html', settings.email_from,
html_content =
loader.get_template('active.html').render()
msg = emailmultialternatives(subject, from_email=from_email, to=
[to])
msg.attach_alternative(html_content, "text/html")
msg.send()
return httpresponse('傳送html的⽂件內容')
Django傳送郵件
簡介 雖然python提供了smtplib庫,來完成email的傳送功能,但是django對其進行了封裝,使得傳送郵件的介面變得更簡單,更方便,django的封裝位於django.core.mail 例子 from django.core.mail import send mail send mai...
django傳送郵件
django封裝了python自帶的傳送郵件的功能,使其更加簡單易用。1 settings中進行配置 email backend django.core.mail.backends.smtp.emailbackend email use tls true email host smtp.163.co...
Django傳送郵件
django提供了傳送郵件的介面,僅需做簡單的設定即可實現傳送郵件的功能。首先需要在setting做簡單的配置,以163郵箱為例 email backend django.core.mail.backends.smtp.emailbackend email host smtp.163.com ema...