我从同一邮件域接收邮件,这是django中的主机邮件

时间:2018-08-18 10:55:49

标签: python django email authentication gmail

这是我的应用的settings.py

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'hk7206210@gmail.com'
EMAIL_HOST_PASSWORD = '*********'
EMAIL_PORT = '587'
EMAIL_USE_TLS = True

forms.py

from django import forms

class contactForm(forms.Form):
    name = forms.CharField(required= True,max_length = 100,help_text = '100 
    character Max.')
    email = forms.EmailField(required = True)
    comment = forms.CharField(widget = forms.Textarea)

views.py

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

if form.is_valid():
    name = form.cleaned_data['name']
    comment = form.cleaned_data['comment']
    subject = 'Message from Matrimonial.com'
    message = '%s %s' %(comment,name)
    emailFrom = form.cleaned_data['email']
    emailTo = [settings.EMAIL_HOST_USER]
    send_mail(subject, message,emailFrom,emailTo)
context = locals()
template = 'contact.html'
return render(request,template,context)

问题是发件人,收件人是来自hk7206210@gmail.com的同一电子邮件地址,也到hk7206210@gmail.com,我搜索了很多但找不到解决方案,请帮我解决这个错误#

1 个答案:

答案 0 :(得分:0)

1)为什么发件人='hk7206210@gmail.com'
您的structure(list(SPECIES = c("Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Grey squirrel", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Red fox", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer", "Roe Deer"), simulation_id = c(74L, 102L, 142L, 121L, 25L, 50L, 67L, 19L, 174L, 46L, 162L, 31L, 199L, 147L, 163L, 18L, 170L, 172L, 106L, 157L, 158L, 200L, 187L, 103L, 144L, 77L, 78L, 139L, 75L, 57L, 171L, 195L, 90L, 136L, 109L, 30L, 152L, 97L, 74L, 8L, 161L, 73L, 130L, 151L, 150L, 184L, 198L, 177L, 97L, 88L, 123L, 190L, 83L, 75L, 143L, 159L, 103L, 16L, 200L, 2L), psi_hat = c(0.526863413764263, 0.525835491514182, 0.526515540307052, 0.526515540305866, 0.525668605170743, 0.526515540309525, 0.491205525300549, 0.526863413760793, 0.527216807861263, 0.526515540305866, 0.526515540306427, 0.526003604543373, 0.526003604547465, 0.527039406294591, 0.491512271725946, 0.526343604414775, 0.526515540311415, 0.490421555053814, 0.526003604541449, 0.526688801109048, 0.79766843868635, 0.801911295111649, 0.797668438685209, 0.79766843868356, 0.736091175845588, 0.801911294988272, 0.797668438684876, 0.797668438686537, 0.764665429923081, 0.806326437262252, 0.769630414385322, 0.806326437300003, 0.733141462334417, 0.801911295128621, 0.777085591061084, 0.801911295171974, 0.703578316906639, 0.777085591642251, 0.793615265014951, 0.806326437459794, 0.662677377511043, 0.701654360968483, 0.704629679152389, 0.70622149033349, 0.663754148939585, 0.704629679094459, 0.705416487515374, 0.677464341430293, 0.707045218951227, 0.662338556587023, 0.674456696561803, 0.701654360967044, 0.639650521202062, 0.625380503760432, 0.704629679094605, 0.664561357366103, 0.704629679143759, 0.636859548660175, 0.66375414894085, 0.707045219029558), p_hat = c(0.305763297214646, 0.315819064091298, 0.309115591855344, 0.309115591855175, 0.317494717397372, 0.309115591855145, 0.326303719905328, 0.305763297214592, 0.302410595448716, 0.309115591855175, 0.309115591855139, 0.314143327866378, 0.314143327866402, 0.304086998925611, 0.322825888575185, 0.310791594807592, 0.309115591855151, 0.335654773573103, 0.314143327866529, 0.307439493743849, 0.0690109229482788, 0.0677020110780009, 0.0690109229483345, 0.0690109229474338, 0.0744703724155286, 0.0677020110840996, 0.0690109229257095, 0.0690109229256593, 0.0704604468308165, 0.0663903378649822, 0.0691283355131073, 0.0663903378091044, 0.0737444081467713, 0.0677020110873479, 0.0665479524846632, 0.0677020110750217, 0.073966658329169, 0.0665479525245426, 0.0703192747621257, 0.0663903375835434, 0.166196509352831, 0.157146399287494, 0.152026850762839, 0.14946227707946, 0.163675003941755, 0.152026850344473, 0.150744974403108, 0.15740696035152, 0.148178744896067, 0.167783160277052, 0.162569260757996, 0.157146399287514, 0.162501076719809, 0.177160578693552, 0.152026850344548, 0.162149934290892, 0.152026850679299, 0.168221557280052, 0.163675003941561, 0.148178745461308)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -60L)) 是您的电子邮件帐户,所有电子邮件都将从该地址发出,因此您的发件人为“ hk7206210@gmail.com”

2)为什么接收者='hk7206210@gmail.com'
因为您写了settings.EMAIL_HOST_USER

您要完成什么?如果要将电子邮件发送给用户在表单中输入的内容,则应该相反:

emailTo = [settings.EMAIL_HOST_USER]