Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- EMAIL_HOST = 'smtp.sendgrid.net'
- EMAIL_HOST_USER = '**'
- EMAIL_HOST_PASSWORD = '***'
- EMAIL_PORT = 587
- EMAIL_USE_TLS = True
- EMAIL_BACKEND = "sgbackend.SendGridBackend"
Add Comment
Please, Sign In to add comment