Django傳送電子郵件

2021-09-24 12:39:04 字數 1788 閱讀 4242

傳送郵件需要依賴郵件服務商提供的郵件伺服器。所以需要開啟郵箱的smtp服務後才可傳送郵件

開啟郵箱的smtp服務,在要用來傳送郵件的郵箱配置中可以開啟或關閉此服務。必須開啟此服務。才可通過編寫**使用此郵箱傳送郵件。

在django專案的settings.py中配置郵件傳送引數

qq郵箱需要設定 email_use_ssl = true

# 郵件配置

email_backend = 'django.core.mail.backends.smtp.emailbackend'

email_host = "smtp.qq.com"

email_port = 465

email_host_user = '*********@qq.com'

email_from = email_host_user

email_host_password = "**********"

# 郵箱連線設定為使用ssl時。需要設定此選項為true,例如qq郵箱預設設定即為此

email_use_ssl = true

163郵箱配置

# 郵件配置

email_backend = 'django.core.mail.backends.smtp.emailbackend'

email_host = "smtp.163.com"

email_port = 25

email_host_user = '*********@163.com'

email_from = email_host_user

email_host_password = "*********"

in [1]: from django.core.mail import send_mail

in [2]: send_mail('這是個郵件的標題', '郵件的內容就在這裡', '********@qq.com'

...: , ['*******@qq.com', '********@vip.qq.com'])

out[2]: 1

in [3]: from django.conf import settings

in [4]: send_mail('這是個郵件的標題', '郵件的內容就在這裡', settings.email_host

...: _user, ['*********@vip.qq.com'])

out[4]: 1

in [5]: from django.core.mail import send_mass_mail

...: ser, ['**********@vip.qq.com'])

in [7]: msg2 = ('話九辰,揮袖風雲盡。江山何沉', '隨三大發送到發史蒂芬發發發第三

...: 方第三方', settings.email_host_user, ['**********@vip.qq.com', '********@

...: qq.com'])

in [8]: send_mass_mail((msg1, msg2))

out[8]: 2

接收的引數為乙個元組。元祖中每個元素都為乙個元組,其中的值的順序與單發郵件的引數順序一致,例如:

send_mass_email((('標題1', '內容1', '傳送郵箱1', ['標題1接郵箱1', '標題1接收郵箱2']), ('標題2', '內容2', '傳送郵箱2', ['標題2接收郵箱1', '標題2接收郵箱2'])))

傳送電子郵件

傳送電子郵件 param emaillist 的物件 param data 傳送的資料 throws ioexception throws addres ception private void sendemail listemaillist,listdata throws ioexception,...

Python傳送電子郵件

源 sendemail.py import smtplib from email.mime.text import mimetext msg mimetext the body of the email is here 這裡是你的信件中的內容 msg from ltoddy 163.com 這裡是傳...

PHP 傳送電子郵件

php 傳送電子郵件 php 允許您從指令碼直接傳送電子郵件。php mail 函式 php mail 函式用於從指令碼中傳送電子郵件。語法 mail to,subject,message,headers,parameters to 必需。規定 email 接收者。subject 必需。規定 ema...