Guest User

Untitled

a guest
Jan 15th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. def contact(request):
  2. title = 'Contact'
  3. form = contactForm(request.POST or None)
  4. confirm_message = None
  5.  
  6. if form.is_valid():
  7. sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY'))
  8. name = form.cleaned_data['name']
  9. comment = form.cleaned_data['comment']
  10. subject = 'Message from **'
  11. content = '%s %s' %(comment, name)
  12. from_email = form.cleaned_data['email']
  13. to_email = Email("***")
  14. try:
  15. mail = Mail(from_email, subject, to_email, content)
  16. response = sg.client.mail.send.post(request_body=mail.get())
  17. except:
  18. title="Sorry!"
  19. confirm_message = "Error sending message, Please try after sometime. Thank you!"
  20. title="Thanks"
  21. confirm_message = "Thanks for the message, We will get right back to you."
  22. form = None
  23.  
  24. context = {'title': title, 'form':form, 'confirm_message': confirm_message,}
  25. template = "contact.html"
  26. return render(request,template,context)
  27.  
  28. EMAIL_HOST = 'smtp.sendgrid.net'
  29. EMAIL_HOST_USER = '**'
  30. EMAIL_HOST_PASSWORD = '***'
  31. EMAIL_PORT = 587
  32. EMAIL_USE_TLS = True
  33. EMAIL_BACKEND = "sgbackend.SendGridBackend"
Add Comment
Please, Sign In to add comment