Python 发送一封电子邮件将变量值传递给 html
Python send an email passing variable value to html
在我的项目中,我必须发送一封电子邮件并将一个值传递给 html 代码。
我试试这个:
l_sender = []
l_sender.append('mario.rossi@test.com')
emailsend(l_sender)
def emailsend(l_sender):
context = {
'news': 'We have good news!'
}
try:
send_html_email(l_sender, 'Get started with Aida', 'email.html', context, sender='wepredict@cathedral.ai')
print("Email send")
except Exception as e:
print(e)
在 email.html 我插入了 {{ context.news }} 但没有出现。
我如何在 mail.html 中传递我的新闻 val 值?
提前致谢
为什么context.news?您必须使用 {{ news }}
。
您调用的函数甚至看不到您的变量名为 context
.
看看这个例子:Creating email templates with Django
在我的项目中,我必须发送一封电子邮件并将一个值传递给 html 代码。 我试试这个:
l_sender = []
l_sender.append('mario.rossi@test.com')
emailsend(l_sender)
def emailsend(l_sender):
context = {
'news': 'We have good news!'
}
try:
send_html_email(l_sender, 'Get started with Aida', 'email.html', context, sender='wepredict@cathedral.ai')
print("Email send")
except Exception as e:
print(e)
在 email.html 我插入了 {{ context.news }} 但没有出现。 我如何在 mail.html 中传递我的新闻 val 值?
提前致谢
为什么context.news?您必须使用 {{ news }}
。
您调用的函数甚至看不到您的变量名为 context
.
看看这个例子:Creating email templates with Django