2017-07-31 87 views
1

我正在通过发送网格从网站的联系表格发送邮件给管理员。该电子邮件是没有得到交付出于某种原因Django,邮件不发送。 Sendgrid

这里是view.py

def contact(request): 
title = 'Contact' 
form = contactForm(request.POST or None) 
confirm_message = None 

if form.is_valid(): 
    sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) 
    name = form.cleaned_data['name'] 
    comment = form.cleaned_data['comment'] 
    subject = 'Message from **' 
    content = '%s %s' %(comment, name) 
    from_email = form.cleaned_data['email'] 
    to_email = Email("***") 
    try: 
     mail = Mail(from_email, subject, to_email, content) 
     response = sg.client.mail.send.post(request_body=mail.get()) 
    except: 
     title="Sorry!" 
     confirm_message = "Error sending message, Please try after sometime. Thank you!" 
    title="Thanks" 
    confirm_message = "Thanks for the message, We will get right back to you." 
    form = None 

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

settings.py

EMAIL_HOST = 'smtp.sendgrid.net' 
EMAIL_HOST_USER = '**' 
EMAIL_HOST_PASSWORD = '***' 
EMAIL_PORT = 587 
EMAIL_USE_TLS = True 
EMAIL_BACKEND = "sgbackend.SendGridBackend" 

电子邮件设在ZOHO ..和我无法收到任何电子邮件

回答

1

首先确保你有sendgrid-django inst alled。然后在你的设置中,它看起来不像你有sendgrid API密钥。尝试下面添加以下内容:

SENDGRID_API_KEY = “你的SendGrid API密钥”

见,如果这个工程。