2015-08-28 118 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方法中。

现在,在您的模板,你写卡恩任何你想要的和邮件应发送