在django发送电子邮件。

时间:2012-04-14 16:42:13

标签: django email smtp

我有一个人们可以提交电子邮件的页面。它有效,但我收到它的所有电子邮件,说它们来自我自己。

以下是观点:

def signup(request):
  if request.method == 'POST': # If the form has been submitted...
    form = SignUpForm(request.POST) # A form bound to the POST data
    if form.is_valid(): # All validation rules pass
        subject = form.cleaned_data['subject']
        message = form.cleaned_data['message']
        sender = form.cleaned_data['sender']
        recipients = ['illuminatirebellion@gmail.com']

        from django.core.mail import send_mail
        send_mail(subject, message, sender, recipients)
        return HttpResponseRedirect('/thanks/') # Redirect after POST
else:
     form = SignUpForm() # An unbound form
return render_to_response('signup.html', {'form': form,},context_instance=RequestContext(request))

设置:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'illuminatirebellion@gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
MANAGERS = ADMINS

1 个答案:

答案 0 :(得分:1)

您对send_mail()的使用似乎是正确的。

假设Gmail是您的SMTP供应商,Gmail似乎不支持使用自定义From:电子邮件地址。

相关: