2015-08-28 138 views
0

我正在開發一個需要發送html郵件的項目。一個url需要插入html內容,如Django的html電子郵件

<p><a href="http://dealerfunnel.com/passwordchange">Password Change Link</a></p> 

我的域名,dealerfunnel.com。如果我把任何有效的網址除http://dealerfunnel.com然後電子郵件發送。就像如果我把

google.com

然後,通過電子郵件發送。但是當我把dealerfunnel.com,電子郵件不發送,並沒有得到任何錯誤。

請檢閱我的代碼:

from dealerfunnel.funnel.view.base import * 
from django.template.loader import get_template 
from django.core.mail import EmailMessage 
import sys 

class debug(): 
    def sendmail(self,request): 
     message = get_template('mail/forgot.html').render(Context({"name":"Khalid Hossain"})) 
     try: 
      msg = EmailMessage('Password Change',message, to=['[email protected]'], from_email='[email protected]') 
      msg.content_subtype = 'html' 
      msg.send() 
      return HttpResponse(message) 
     except : 
      e = sys.exc_info()[0] 
      return HttpResponse(e) 
+2

爲什麼不使用Django的[重置密碼](https://docs.djangoproject.com/en/1.8/topics/auth /default/#module-django.contrib.auth.views)表單? – Sayse

+0

顯示你的settings.py – fledgling

+0

和你的網址,你不應該硬編碼一個頁面鏈接,你應該使用'url'模板標籤 – Sayse

回答

0

這裏是什麼ü可以做

def send_notification_email(template, **kwargs): 
    subject = "Your subject here" 
    context = Your_Context 
    email = Your_Email 
    body = render_to_string(template, {'context':context}) 
    return send_mail(subject, body, settings.EMAIL_HOST_USER, [email], fail_silently=True) 

這是,如果你的是從您的視圖調用此函數.. 如果沒有,那麼你可以使用模板顯式地在send_mail方法中。

現在,在您的模板,你寫卡恩任何你想要的和郵件應發送