1 / 14

Brett DiDonato email: brett@giftivo twitter: @giftivo

B uilding an Automated Email System w ith Django and AWS. Brett DiDonato email: brett@giftivo.com twitter: @giftivo. Agenda. Configure AWS Simple Email Services (SES) Configure AWS Elastic Cloud Compute (EC2) Creating an Email System Sending Emails With Python & Django

eytan
Download Presentation

Brett DiDonato email: brett@giftivo twitter: @giftivo

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building an Automated Email System with Django and AWS Brett DiDonato email: brett@giftivo.com twitter: @giftivo

  2. Agenda • Configure AWS Simple Email Services (SES) • Configure AWS Elastic Cloud Compute (EC2) • Creating an Email System • Sending Emails With Python & Django • Tracking Opens & Unsubscribes • Open Email In Browser • Scheduling With Cron • Formatting Emails – Best Practices • Personalizing The Experience • Case Study: Email Reminder System

  3. Configure AWS SES • Test Settings – Verify Individual Email Addresses • Production Settings – Verify Domain • DNS – AWS Route 53

  4. Configure AWS EC2 • Launch an instance • Configure Apache, Python, Python Libraries, Django, MongoDB • Start Apache & MongoDB • Install Python library boto – used for SES and other AWS functions

  5. Configure SES With Python • 1. Create /etc/boto.cfg file: • [Credentials] • aws_access_key_id = your-key-here • aws_secret_access_key = your-secret-here • 2. Sending emails: • import boto • conn = boto.connect_ses() • response = conn.send_email( • source=“Name <from@domain.com>", • subject=emailSubject, • body=emailBody, • format="html", • to_addresses=[listOfToEmails] • )

  6. Configure SES With Django • Install django-ses • Add key, secret and SES reference to settings.py: • aws_access_key_id = your-key-here • aws_secret_access_key = your-secret-here • EMAIL_BACKEND = ‘django_ses.SESBackend’ • 3. Sending Emails: • from django.core.mail import send_mail • send_mail( • ‘Subject’, • ‘Body’, • ‘from@domain.com’, • [listOfToEmails], • fail_silently=False • )

  7. Track Opens • Embed image in email body with URL pointing towards Django server address: <img src=“mywebsite.com/email_img/campaign/identifier” /> • urls.py: (r'^email_img/(?P<campaign>.*)/(?P<identifier>.*)$', email_img), • Log read event and serve image: • from PIL import Image • from datetime import datetime • from pymongo import Connection • connection = Connection() • def email_img(response, campaign, identifier): • myDict = {} • myDict['campaign'] = campaign • myDict['identifier'] = identifier • myDict['read_timestamp'] = datetime.now() • connection.dbName.trackEmails.insert(myDict) • image = Image.open(“/directory/for/my-image.gif") • transparent = image.info["transparency"] • response = HttpResponse(mimetype="image/gif") • image.save(response, "gif", transparency=transparent) • return response

  8. Track Unsubscribes • Embed link in email body with URL pointing towards Django server address: <a href=http://mywebsite.com/unsubscribe/userid>Unsubscribe</a> • urls.py: (r'^unsubscribe/(?P<campaign>.*)/(?P<userid>.*)$', email_tracking_file), • Log unsubscribe event and return confirmation response (probably want to actually confirm it): • from pymongo import Connection • connection = Connection() • def unsubscribe(response, userid): • connection.dbName.userCollection.update({"userid":userid},{"$set":{"unsubscribed":True}}) • return HttpResponse("unsubscribed")

  9. Open Email in Browser • In the email body include a link to view the email in the browser: <a href=“http://mywebsite.com/campaign/userid”>View This Email In Your Browser</a> • Urls.py: (r'^email_in_browser/(?P<campaign>.*)/(?P<userid>.*)$', email_tracking_file), • Log unsubscribe event and return confirmation response (probably want to actually confirm it): • def email_in_browser(response, campaign, userid): • … • return HttpResponse(emailBody)

  10. Scheduling with Cron • Open cron table: crontab –e • Run job daily at midnight… 0 0 * * * python /directory/for/email_script.py • Log file: /var/log/cron

  11. Formatting Emails – Best Practices • No JavaScript • GIF or JPG Images • HTML Tables • Inline CSS • Max width ~600px • Avoid “spammy” words (in subject especially) • Test with major email providers: Gmail, Yahoo!, Outlook, Hotmail/Outlook.com, AOL

  12. Personalizing the Experience • Build something that adds value • Give the user control • Personalized subject & body: • Name • Age • Sex • Browsing history • Shopping history • Location – pygeoip • import pygeoip • ip = response.META['REMOTE_ADDR'] • gi = pygeoip.GeoIP('/usr/local/share/GeoIP/GeoIP.dat', pygeoip.MEMORY_CACHE) • country = gi.country_code_by_name(ip)

  13. Case Study: Email Reminder System • Users log in to website and configure important life events • Event details stored in MongoDB • Cron job scheduled once per day against reminder events for current day • Database logging and events updated • Emails sent with personalized email subject and body • Track opens and provide “view in browser” link • Try it out at giftivo.com, log in, click red “reminders” button, configure reminders, click “Get A Gift Now” to view email in browser

  14. Building an Automated Email System with Django and AWS • Get the notes from this presentation: • giftivo.com/djangonyc Brett DiDonato email: brett@giftivo.com twitter: @giftivo

More Related