目前,我有一个在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
在我看来,我有:
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.")
当我打开邮件时,我会在标题中看到这个:
FromEmail@example.com via amazonses.com
我想自定义这个,以便我可以这样做:
UserFirstName UserLastName via amazonses.com
我将如何做到这一点?
答案 0 :(得分:3)
我怀疑你可以,但你应该可以使用这样的地址:
email_message = EmailMessage('This is a title', 'This is a message body', 'UserFirstName UserLastName <FromEmail@example.com>', ['ToEmail@example.com'])
应该会导致电子邮件客户端显示如下地址:
UserFirstName UserLastName <FromEmail@example.com>