django发送电子邮件问题

时间:2017-05-19 13:51:15

标签: python django

我知道有类似的问题,但我的问题很奇怪。我在联系页面提交的电子邮件没有收到。相反,我收到了电子邮件中的电子邮件。

这是我在settings.py中所做的:

              EMAIL_HOST='smtp.gmail.com'
              EMAIL_HOST_USER= 'my gmail adress'
              EMAIL_HOST_PASSWORD= 'my password'
              EMAIL_PORT='587'
              EMAIL_USE_TLS=True
在views.py -contact

    from django.shortcuts import render
    from django.core.mail import send_mail
    from django.conf import settings
    from .forms import contactForm
    # Create your views here.
    def contact(request):
        title = 'Contact Us'
        form = contactForm(request.POST or None)
        comfirm_message=None

        if form.is_valid():
            name = form.cleaned_data['name']
            comment = form.cleaned_data['comment']
            subject = 'Message from a user of Archives Manager'
            emailFrom = form.cleaned_data['email']

            message = '%s %s' % (comment, name)

            emailTo = [settings.EMAIL_HOST_USER]
            send_mail(subject, message, emailFrom, emailTo, fail_silently=True)
            title = "Thanks!"
            comfirm_message='Thanks for the message. we will get right back to you.'
            form=None

        context = {'title': title, 'form' : form, 'comfirm_message': comfirm_message, }
        template = 'contact.html'
        return render(request,template,context)

我在我的Gmail帐户中收到的是来自我的电子邮件地址的邮件,而不是我在EmailField()中提交的邮件?

    from django import forms

    class contactForm(forms.Form):
        name = forms.CharField(required=False,max_length=100, help_text="100 is the maximum length" )
        email = forms.EmailField(required=True)
        comment = forms.CharField(required=True,widget=forms.Textarea)

0 个答案:

没有答案
相关问题