通过Django电子邮件发送时链接不可单击

通过Django电子邮件发送时链接不可单击,django,email,gmail,Django,Email,Gmail,当网站发送电子邮件时,它会使用a标记创建链接。出于某种原因,gmail(可能还有其他电子邮件)不会将a标签包含的文本转换为链接 发送电子邮件的功能: def send_main(to, sbj, msg): msg = EmailMultiAlternatives(sbj, msg, '********@gmail.com', to) msg.content_subtype = "html" msg.send() 在shell中传递到电子邮件的参数 send_main(

当网站发送电子邮件时,它会使用
a
标记创建链接。出于某种原因,gmail(可能还有其他电子邮件)不会将
a
标签包含的文本转换为链接

发送电子邮件的功能:

def send_main(to, sbj, msg):
    msg = EmailMultiAlternatives(sbj, msg, '********@gmail.com', to)
    msg.content_subtype = "html"
    msg.send()
在shell中传递到电子邮件的参数

send_main(['****@gmail.com'], 'test', '<a href="http://www.google.com"/>test</a>')
send_main(['***@gmail.com'],'test','')
然而,当我在python shell中执行该行时,它会发送电子邮件,但gmail无法识别该链接。

使用以下方法:

html_content = render_to_string('emails/email_%s.html' % template_name, { parmas })
message = EmailMultiAlternatives(subject, html_content, settings.GENERIC_EMAIL_SENDER,[email])
message.attach_alternative(html_content, 'text/html')
message.send()

将其传递到HTML模板中,并调用render_to_string-确保附件为“text/HTML”,并且应该可以正常工作。

它不可单击,因为某些邮件站点会阻止href,但这在gmail中可以工作 要使这些站点中的链接可点击,请使用send_mail

from django.core.mail import send_mail

send_mail('Subject', 'http://www.google.com', 'from@example.com',
['to@example.com'], fail_silently=False)

希望这能起作用

对于
内容子类型
技巧,文档直接使用
电子邮件
。这可能是问题所在吗?它使用EmailMultiAlternatives来实际附加2个Payloads,但我想不可能在那里写锚定标记?