我正在使用Sendgrid向Django发送电子邮件。对于要发送的消息,我有一个变量message
,但message
保存了一些其他变量的值。我希望他们能够在不同的行上使电子邮件更容易阅读。这就是我所拥有的,虽然它不起作用。
if form.is_valid():
name = form.cleaned_data.get('name')
phone = form.cleaned_data.get('phone')
email = form.cleaned_data.get('email')
party_size = form.cleaned_data.get('party_size')
form_message = form.cleaned_data.get('message')
listing_address = listing.address
message = name + "\n" + phone + "<br>" + email + "<br>" + party_size + "<br>" + listing_address
send_mail('New Lead', message, 'to email', ['email@gmail.com'], fail_silently=False)
电子邮件的发送方式如下:
garrett 1234234<br>g@d.com<br>2<br>address would be here
虽然我想这样:
garrett
1234234
g@d.com
2
address would be here
答案 0 :(得分:1)
最好的方法是创建电子邮件模板&amp;为电子邮件模板提供上下文,然后使用生成电子邮在send_email
中使用此内容(generated_html)
作为参数html_message
send_mail('New Lead', message, 'to email',
['email@gmail.com'], fail_silently=False, html_message=genenrated_html)
答案 1 :(得分:0)
您可以使用 EmailMessage发送HTML版电子邮件:
from django.core.mail import EmailMessage
message = name + "<br>" + phone + "<br>" + email + "<br>" + party_size + "<br>" + listing_address
msg = EmailMessage(subject, message, from_email, ['email@gmail.com'])
msg.content_subtype = "html" # Main content is now text/html
msg.send()
答案 2 :(得分:0)
答案 3 :(得分:0)
trata utilizando el siguiente codigo:
Dialog