2017-07-31 141 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密鑰」

見,如果這個工程。