Skip to content

Instantly share code, notes, and snippets.

@chriskief
Created October 24, 2013 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriskief/7130488 to your computer and use it in GitHub Desktop.
Save chriskief/7130488 to your computer and use it in GitHub Desktop.
from app.lib.amazonses import SESMessage
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
# grab the form data
name = form.cleaned_data['name']
email = form.cleaned_data['email']
subject = form.cleaned_data['subject']
body = form.cleaned_data['body']
recipient = 'recipient@site.com'
# render the template with the submitted data
rendered = render_to_string('email/contact.html', {'name': name, 'email': email, 'subject': subject, 'body': body})
# create the message and send the email
# the from address must be a verified sender in SES
msg = SESMessage('valid_sending_address@site.com', recipient, subject)
msg.text = rendered
msg.html = rendered + ' html'
msg.send()
messages.add_message(request, messages.INFO, 'Your contact enquiry was successfully sent. Thank you!')
return HttpResponseRedirect(reverse('contact'))
else:
form = ContactForm()
return render(request, 'contact.html', {'form': form})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment