2017-07-31 3 views
1

私は送付状を介してWebサイトから連絡フォームから管理者にメールを送信するようにしています。メールはここDjango、Mail not sending。 Sendgrid

は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サービスに設定されている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) 

で、何らかの理由で配信取得されていません。..と私は電子メールを受け取ることができません

答えて

1

最初にsendgrid-django inst alled。あなたの設定では、sendgrid APIキーを持っているようには見えません。以下、次を追加しよう:

SENDGRID_API_KEY = "あなたのSendGrid APIキー"

これが動作するかどうかを参照してください。

関連する問題