在 Django 中通过 Amazon SES 发送电子邮件时如何更改显示名称?

Mic*_*ith 3 python django amazon-ses

目前,我有一个在 Django 中使用 Amazon SES 发送电子邮件的有效实现。

我的设置看起来像这样。在 settings.py 中我有:

EMAIL_HOST = 'email-smtp....'
EMAIL_PORT = 25
EMAIL_HOST_USER = 'my-email-host-user'
EMAIL_HOST_PASSWORD = 'my-email-host-password'
EMAIL_USE_TLS = True
Run Code Online (Sandbox Code Playgroud)

在我看来我有:

from django.shortcuts import render
from django.http import HttpResponse
from django.conf import settings
from django.contrib import messages
from django.core.mail import send_mail
from django.core.mail import EmailMessage

def index(request):
    email_message = EmailMessage('This is a title', 'This is a message body', 'FromEmail@example.com', ['ToEmail@example.com'])
    email_message.send()
    return HttpResponse("You just sent an email message.")
Run Code Online (Sandbox Code Playgroud)

当我打开邮件时,我在标题中看到以下内容:

FromEmail@example.com via amazonses.com 
Run Code Online (Sandbox Code Playgroud)

我想定制这个,以便我可以做这样的事情:

UserFirstName UserLastName via amazonses.com
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

mha*_*wke 5

我怀疑你可以,但你应该能够从这样的地址使用:

email_message = EmailMessage('This is a title', 'This is a message body', 'UserFirstName UserLastName <FromEmail@example.com>', ['ToEmail@example.com'])
Run Code Online (Sandbox Code Playgroud)

这应该会导致电子邮件客户端显示发件人地址,如下所示:

用户名 用户姓氏 <FromEmail@example.com>