Python django发送电子邮件问题

Python django发送电子邮件问题,python,django,Python,Django,我知道也有类似的问题,但我的问题很奇怪。我在联系人页面中提交的电子邮件不会被发送。相反,我会从电子邮件中收到一封电子邮件 以下是我在settings.py中所做的操作: EMAIL_HOST='smtp.gmail.com' EMAIL_HOST_USER= 'my gmail adress' EMAIL_HOST_PASSWORD= 'my password' EMAIL_PORT=

我知道也有类似的问题,但我的问题很奇怪。我在联系人页面中提交的电子邮件不会被发送。相反,我会从电子邮件中收到一封电子邮件

以下是我在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中-联系

    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()中提交的邮件


我想你想要的是
emailTo=form.cleanned\u data['email']
,然后设置
emailFrom=settings.email\u HOST\u USER
。也许我遗漏了什么。谷歌将把发件人改成你的帐户。如果您想使用其他发件人地址发送邮件,请使用您自己的邮件服务器。但是,希望邮件经常被过滤为垃圾邮件。好吧,可能是因为应用程序的安全性较低,emailFrom被更改为Email\u HOST\u用户
    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)