Smtp 正确使用sendgrid
我正在使用Python sendgrid库发送电子邮件。 然而,我有一些奇怪的问题 我在Sendgrid上创建了一个模板,并使用该模板id发送电子邮件 但是,在python代码中,我需要: 1.调用set_subject(..),即使我不想修改主题。我理解这是因为模板中必须存在。是否有一种方法可以选择不在模板中指定并避免set_subject(parameters)函数调用?(现在我用空字符串调用set_subject。)Smtp 正确使用sendgrid,smtp,sendgrid,Smtp,Sendgrid,我正在使用Python sendgrid库发送电子邮件。 然而,我有一些奇怪的问题 我在Sendgrid上创建了一个模板,并使用该模板id发送电子邮件 但是,在python代码中,我需要: 1.调用set_subject(..),即使我不想修改主题。我理解这是因为模板中必须存在。是否有一种方法可以选择不在模板中指定并避免set_subject(parameters)函数调用?(现在我用空字符串调用set_subject。) set_text(..)也是如此。同样,这是因为必须存在于模板中。是否有
import sendgrid
def send_twitch_welcome_message(user_name, user_email, confirmation_url=None): if not sg:
return 500, 'SendGrid not configured'
message = sendgrid.Mail()
message.add_filter('templates', 'enable', '1')
message.add_filter('templates', 'template_id',
some_template_id)
message.add_to(desired_email_idl)
message.set_from(my_email_id)
message.set_subject(' ')
message.set_text(' ')
message.set_html("""
<h3 style="margin-bottom: 20px; font-size:18px; color:#000000;
font-family:tahoma,geneva,sans-serif; font-weight:normal;">
Something !</h3>
""") # This works fine, but commenting this function call leads to text-only email
message.add_substitution('key', value)
status, msg = sg.send(message)
return status, msg
导入sendgrid
def发送twitch欢迎消息(用户名、用户电子邮件、确认url=None):如果不是sg:
返回500,“未配置SendGrid”
message=sendgrid.Mail()
消息。添加过滤器('templates','enable','1')
message.add_filter('templates','template_id',
一些(模板id)
消息。添加到(所需的电子邮件\u idl)
message.set_from(我的电子邮件id)
消息。设置主题(“”)
message.set_文本(“”)
message.set_html(“”)
某物
“”“”)#这很好,但对该函数调用进行注释会导致出现纯文本电子邮件
消息。添加替换('key',value)
状态,msg=sg.send(消息)
返回状态,msg
您也可以在SendGrid Python GitHub repo上问这个问题,这样库维护人员就可以看一看了。:)谢谢你。我这样做了:你能在SendGrid Python GitHub repo上问这个问题吗,这样库维护人员就可以看一看了。:)谢谢你。我做到了: