0

django多后端发送邮件

 2 years ago
source link: https://blog.51cto.com/u_13366251/5564676
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

django多后端发送邮件

原创

👉 ​ ​自定义邮件后端​

主要针对 EmailMessage 内 connection 参数的使用

from django.core.mail import EmailMessage
from django.core.mail.backends.smtp import EmailBackend


def send(subject: str, content: str, send_mailer: str,
receive_mailer: list, host: str, username: str,
password: str) -> int:
em_obj = EmailMessage(
subject,
content,
send_mailer,
receive_mailer,
connection=EmailBackend(
host=host,
username=username,
password=password,
)
)
return em_obj.send()


if __name__ == '__main__':
params = {
'subject': '主题',
'content': '内容',
'send_mailer': '发件人',
'receive_mailer': ['收件人1', '收件人2'],
'host': 'smtp.qq,com', # 按需切换不同邮件服务器
'username': '认证账户名称',
'password': '认证账户密码',
}
send(**params)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK