2013-07-31 18 views
1
confirm_links = 'To confirm this order http://mywebsite.com ' 
deny_links = '\nTo deny this order http://mywebsite.com 

email=EmailMessage('title_text', confirm_links+deny_links, to=['[email protected]']) 
email.send() 
signals.post_save.connect(send_email_on_new_order, sender= PurchaseOrder, dispatch_uid = 'send_email_on_new_order') 

我的程序發送一個鏈接,在那裏他們可以單擊這兩條鏈路確認或否認他們的訂單用戶的電子郵件程序。我想使它在哪裏,他們沒有看到行http://mywebsite.com,而只是看到「訂單」超鏈接,其中去http://mywebsite.com製作發送該超鏈接在Django文本

+0

你不知道如何做一個HTML鏈接? ... –

+1

A correction link tag is 'blabla' –

回答

3

報價從docs

默認情況下,MIME類型在EmailMessage機體參數是 「text/plain的」

把你的鏈接在<a>標籤和設置email.content_subtype = "html"

confirm_links = 'To confirm this <a href="http://mywebsite.com">order</a>' 
deny_links = '\nTo deny this <a href="http://mywebsite.com">order</a>' 
email=EmailMessage('title_text', confirm_links+deny_links, to=['[email protected]']) 
email.content_subtype = "html" 
email.send() 

但是,它的發送郵件的文本和HTML版本,一個很好的做法。考慮使用EmailMultiAlternatives

0

如果你只是想做一個經典的鏈接,你只需要使用HTML <a>標籤。此外,如果你想指向一個特定的網址,你可以使用reverse()功能(見documentation about URL

還設置email.content_subtype = "html"