email_backend =
'django.core.mail.backends.smtp.emailbackend'
email_use_tls =
false
email_use_ssl =
false
email_host =
'smtp.163.com'
email_port =
25email_host_user =
'*********[email protected]'
# 郵箱賬號
email_host_password =
'**********'
# 郵箱密碼
email_subject_prefix =
'mail test'
# 為郵件標題的字首,預設是'[django]'
default_from_email =
'*********[email protected]'
# 傳送郵件
subject =
'郵件主題'
content =
'郵件正文'
to_addr =
'*********@163.com'
# 收件人
attach = filename # 附件 檔案路徑字串
sendmail(subject=subject, content=content, to_addr=to_addr, attach=attach)
# 呼叫郵件傳送函式
defsendmail
(subject=
none
, content=
none
, from_email=
'*********[email protected]'
, to_addr=
none
, attach=
none):
print
('start send email to %s'
)# send_mail的引數分別是 郵件標題,郵件內容,發件箱(settings.py中設定過的那個),收件箱列表(可以傳送給多個人),失敗靜默(若傳送失敗,報錯提示我們)
# send_mail('鏈結檢測結果', 'here is the message.', '******[email protected]',
# ['[email protected]'], fail_silently=false)
msg = emailmultialternatives(subject, content, from_email, to_addr)
print
(to_addr)
# 新增附件(可選)
msg.attach_file(attach)
# 傳送郵件
msg.send(
)print
('success'
)
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...