ujj*_*wal 4 python sendgrid sendgrid-api-v3
我正在尝试使用 Sendgrid Python 包发送电子邮件。
Sendgrid封装邮件功能:
class Mail(object):
"""Creates the response body for v3/mail/send"""
def __init__(
self,
from_email=None,
to_emails=None,
subject=None,
plain_text_content=None,
html_content=None,
amp_html_content=None,
global_substitutions=None,
is_multiple=False):
........
Run Code Online (Sandbox Code Playgroud)
我们将其用作:
message = Mail(
from_email=self.current_from_email,
to_emails=self.current_to_emails,
subject=s_subject.format(...),
html_content=s_body.format(...)
)
Run Code Online (Sandbox Code Playgroud)
在邮件功能中无法设置发件人姓名。
那么,如何设置发件人姓名呢?
phi*_*ash 16
Twilio SendGrid 开发人员布道者在这里。
要设置发件人的姓名,您有几个选项。首先,您可以像这样格式化电子邮件地址Sender name <sender_email@example.com>。
或者,您可以从帮助程序中导入Email, orFrom和, 并使用它:To
from sendgrid.helpers.mail import From, To
from_email = From("sender_email@example.com", "Sender Name")
to_email = To("receiver_email@example.com", "Receiver Name")
message = Mail(from_email, to_email, "Subject", "Content")
Run Code Online (Sandbox Code Playgroud)
请参阅GitHub README 中的示例,了解更多可以使用的类助手。