[Python] Django mail engine usage Detailed! ! (Call 163 E-mail, for example)

1.

send_mall()Methods Introduction

  • position:
    • In the django.core.mailmodule provides send_mail()to send mail.
  • Method parameters:
    • send_mail(subject, message, from_email, recipient_list, html_message=None)
subject 邮件标题
message 普通邮件正文,普通字符串
from_email 发件人
recipient_list 收件人列表
html_message 多媒体邮件正文,可以是html字符串

2. Prepare the mail server

1. Click into the "Settings" interface

 

2. Click into the "Client Authorization Codes" screen

 

3. Open the "authorization code", and complete the verification text messages

 

4. Fill out the "Authorization Code"

 

5. Complete "license key" provided

 

6. Configure mail server setting. py set

= EMAIL_BACKEND 'django.core.mail.backends.smtp.EmailBackend' 
EMAIL_HOST = 'smtp.163.com' 
EMAIL_PORT = 25 
# E-mail mailbox 
EMAIL_HOST_USER = '[email protected]' 
# in the mailbox provided client licensing password 
EMAIL_HOST_PASSWORD = 'xxxxxx' 
# recipient sees the sender 
EMAIL_FROM = 'a certain server <[email protected]>'

  

7. Transmit mailbox function is defined

from django.conf import settings
from django.core.mail import send_mail

def send_verify_email(self, to_email, verify_url):
    """
    发送验证邮箱邮件
    :param to_email: 收件人邮箱
    :param verify_url: 验证链接
    :return: None
    """
    subject = "xxx软件邮箱验证"
    html_message = '<p>尊敬的用户您好!</p>' \
                   '<p>感谢您使用xxx。</p>' \
                   '<p>您的邮箱为:%s 。请点击此链接激活您的邮箱:</p>' \
                   '<p><a href="%s">%s<a></p>' % (to_email, verify_url, verify_url)
    try:
        send_mail(subject, "", settings.EMAIL_FROM, [to_email], html_message=html_message)

  

 
 

Guess you like

Origin www.cnblogs.com/LiuXinyu12378/p/11241563.html
Recommended