2013-01-22 61 views
0

當網站發送電子郵件時,它使用a標籤創建鏈接。出於某種原因,gmail(可能的其他電子郵件)也不會將a標籤包含的文本轉換爲鏈接。通過Django電子郵件發送時鏈接不可點擊

功能用於發送電子郵件:

def send_main(to, sbj, msg): 
    msg = EmailMultiAlternatives(sbj, msg, '********@gmail.com', to) 
    msg.content_subtype = "html" 
    msg.send() 

PARAMATERS通過在外殼

send_main(['****@gmail.com'], 'test', '<a href="http://www.google.com"/>test</a>') 

,當我在Python shell中執行行至電子郵件了,它發出的電子郵件,但Gmail無法識別的鏈接。

+0

的docs直接使用'EmailMessage',用於'content_subtype'技巧。這可能是問題嗎?它使用EmailMultiAlternatives實際附加2個有效載荷 –

回答

1

使用此方法:

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的」,它應該工作的罰款。

0

它無法點擊,因爲一些郵件網站將阻止HREF,但是這將在Gmail中 工作,使鏈接點擊這些網站使用send_mail代替

from django.core.mail import send_mail 

send_mail('Subject', 'http://www.google.com', '[email protected]', 
['[email protected]'], fail_silently=False) 

希望這將工作

相關問題