SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Building an Automated Email System 
with Django and AWS 
Brett DiDonato 
email: brett at brettdidonato dot com 
twitter: @brettdidonato
Agenda 
1. Configure AWS Simple Email Services (SES) 
2. Configure AWS Elastic Cloud Compute (EC2) 
3. Creating an Email System 
a. Sending Emails With Python & Django 
b. Tracking Opens & Unsubscribes 
c. Open Email In Browser 
d. Scheduling With Cron 
e. Formatting Emails – Best Practices 
f. Personalizing The Experience 
4. Case Study: Email Reminder System
Configure AWS SES 
1. Test Settings – Verify Individual Email Addresses 
2. Production Settings – Verify Domain 
3. DNS – AWS Route 53
Configure AWS EC2 
1. Launch an instance 
2. Configure Apache, Python, Python Libraries, Django, MongoDB 
3. Start Apache & MongoDB 
4. Install Python library boto – used for SES and other AWS functions
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] 
)
Configure SES With Django 
1. Install django-ses 
2. 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 
)
Track Opens 
1. Embed image in email body with URL pointing towards Django server address: 
<img src=“mywebsite.com/email_img/campaign/identifier” /> 
2. urls.py: (r'^email_img/(?P<campaign>.*)/(?P<identifier>.*)$', email_img), 
3. 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
Track Unsubscribes 
1. Embed link in email body with URL pointing towards Django server address: 
<a href=http://mywebsite.com/unsubscribe/userid>Unsubscribe</a> 
2. urls.py: (r'^unsubscribe/(?P<campaign>.*)/(?P<userid>.*)$', email_tracking_file), 
3. 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")
Open Email in Browser 
1. 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> 
2. Urls.py: (r'^email_in_browser/(?P<campaign>.*)/(?P<userid>.*)$', email_tracking_file), 
3. Log unsubscribe event and return confirmation response (probably want to actually confirm it): 
def email_in_browser(response, campaign, userid): 

 
return HttpResponse(emailBody)
Scheduling with Cron 
1. Open cron table: 
crontab –e 
2. Run job daily at midnight
 
0 0 * * * python /directory/for/email_script.py 
Log file: 
/var/log/cron 
Note: consider using a CRON alternative like Celery for more advanced 
use cases
Formatting Emails – Best Practices 
1. No JavaScript 
2. GIF or JPG Images 
3. HTML Tables 
4. Inline CSS 
5. Max width ~600px 
6. Avoid “spammy” words (in subject especially) 
7. Test with major email providers: Gmail, Yahoo!, Outlook, 
Hotmail/Outlook.com, AOL
Personalizing the Experience 
1. Build something that adds value 
2. Give the user control 
3. Personalized subject & body: 
1. Name 
2. Age 
3. Sex 
4. Browsing history 
5. Shopping history 
6. 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)
Case Study: Email Reminder System 
1. Users log in to website and configure important life events 
2. Event details stored in MongoDB 
3. Cron job scheduled once per day against reminder events for current day 
4. Database logging and events updated 
5. Emails sent with personalized email subject and body 
6. Track opens and provide “view in browser” link 
7. Try it out at giftivo.com, log in, click red “reminders” button, configure 
reminders, click “Get A Gift Now” to view email in browser
Building an Automated Email System 
with Django and AWS 
Thanks! 
Brett DiDonato 
email: brett at brettdidonato dot com 
twitter: @brettdidonato

Weitere Àhnliche Inhalte

Ähnlich wie Building an automated email system with django and aws

NZYP Project Casestudy using SilverStripe CMS
NZYP Project Casestudy using SilverStripe CMSNZYP Project Casestudy using SilverStripe CMS
NZYP Project Casestudy using SilverStripe CMSCam Findlay
 
Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Arjan
 
Session 4 StudioX EMEA email automation.pdf
Session 4 StudioX EMEA email automation.pdfSession 4 StudioX EMEA email automation.pdf
Session 4 StudioX EMEA email automation.pdfCristina Vidu
 
LAPHP/LAMPSig Talk: Intro to SendGrid - Building a Scalable Email Infrastructure
LAPHP/LAMPSig Talk: Intro to SendGrid - Building a Scalable Email InfrastructureLAPHP/LAMPSig Talk: Intro to SendGrid - Building a Scalable Email Infrastructure
LAPHP/LAMPSig Talk: Intro to SendGrid - Building a Scalable Email InfrastructureSendGrid
 
6 Things You Didn't Know About Firebase Auth
6 Things You Didn't Know About Firebase Auth6 Things You Didn't Know About Firebase Auth
6 Things You Didn't Know About Firebase AuthPeter Friese
 
Building apps for microsoft teams - aossg
Building apps for microsoft teams - aossgBuilding apps for microsoft teams - aossg
Building apps for microsoft teams - aossgJenkins NS
 
Android ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codesAndroid ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codesAravindharamanan S
 
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Startedguest1af57e
 
Authentication
AuthenticationAuthentication
Authenticationsoon
 
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDays
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDaysBuild and deploy PyTorch models with Azure Machine Learning - Henk - CCDays
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDaysCodeOps Technologies LLP
 
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...Shift Conference
 
MozCon Seattle 2011 - Social Design
MozCon Seattle 2011 - Social DesignMozCon Seattle 2011 - Social Design
MozCon Seattle 2011 - Social DesignMat Clayton
 
Mobile, web and cloud - the triple crown of modern applications
Mobile, web and cloud -  the triple crown of modern applicationsMobile, web and cloud -  the triple crown of modern applications
Mobile, web and cloud - the triple crown of modern applicationsIdo Green
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your App
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your AppOdoo Experience 2018 - Inherit from These 10 Mixins to Empower Your App
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your AppElĂ­nAnna JĂłnasdĂłttir
 
App engine devfest_mexico_10
App engine devfest_mexico_10App engine devfest_mexico_10
App engine devfest_mexico_10Chris Schalk
 
JavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeJavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeLaurence Svekis ✔
 
ASP.NET Lecture 5
ASP.NET Lecture 5ASP.NET Lecture 5
ASP.NET Lecture 5Julie Iskander
 

Ähnlich wie Building an automated email system with django and aws (20)

NZYP Project Casestudy using SilverStripe CMS
NZYP Project Casestudy using SilverStripe CMSNZYP Project Casestudy using SilverStripe CMS
NZYP Project Casestudy using SilverStripe CMS
 
Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013Zotonic tutorial EUC 2013
Zotonic tutorial EUC 2013
 
Session 4 StudioX EMEA email automation.pdf
Session 4 StudioX EMEA email automation.pdfSession 4 StudioX EMEA email automation.pdf
Session 4 StudioX EMEA email automation.pdf
 
LAPHP/LAMPSig Talk: Intro to SendGrid - Building a Scalable Email Infrastructure
LAPHP/LAMPSig Talk: Intro to SendGrid - Building a Scalable Email InfrastructureLAPHP/LAMPSig Talk: Intro to SendGrid - Building a Scalable Email Infrastructure
LAPHP/LAMPSig Talk: Intro to SendGrid - Building a Scalable Email Infrastructure
 
6 Things You Didn't Know About Firebase Auth
6 Things You Didn't Know About Firebase Auth6 Things You Didn't Know About Firebase Auth
6 Things You Didn't Know About Firebase Auth
 
Building apps for microsoft teams - aossg
Building apps for microsoft teams - aossgBuilding apps for microsoft teams - aossg
Building apps for microsoft teams - aossg
 
Android ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codesAndroid ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codes
 
The Big Picture and How to Get Started
The Big Picture and How to Get StartedThe Big Picture and How to Get Started
The Big Picture and How to Get Started
 
Jquery
JqueryJquery
Jquery
 
Authentication
AuthenticationAuthentication
Authentication
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDays
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDaysBuild and deploy PyTorch models with Azure Machine Learning - Henk - CCDays
Build and deploy PyTorch models with Azure Machine Learning - Henk - CCDays
 
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
Shift Remote AI: Build and deploy PyTorch Models with Azure Machine Learning ...
 
MozCon Seattle 2011 - Social Design
MozCon Seattle 2011 - Social DesignMozCon Seattle 2011 - Social Design
MozCon Seattle 2011 - Social Design
 
Mobile, web and cloud - the triple crown of modern applications
Mobile, web and cloud -  the triple crown of modern applicationsMobile, web and cloud -  the triple crown of modern applications
Mobile, web and cloud - the triple crown of modern applications
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your App
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your AppOdoo Experience 2018 - Inherit from These 10 Mixins to Empower Your App
Odoo Experience 2018 - Inherit from These 10 Mixins to Empower Your App
 
App engine devfest_mexico_10
App engine devfest_mexico_10App engine devfest_mexico_10
App engine devfest_mexico_10
 
JavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive CodeJavaScript DOM - Dynamic interactive Code
JavaScript DOM - Dynamic interactive Code
 
ASP.NET Lecture 5
ASP.NET Lecture 5ASP.NET Lecture 5
ASP.NET Lecture 5
 

KĂŒrzlich hochgeladen

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp KrisztiĂĄn
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 

KĂŒrzlich hochgeladen (20)

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ đŸ„ Women's Abortion Clinic In Pre...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 

Building an automated email system with django and aws

  • 1. Building an Automated Email System with Django and AWS Brett DiDonato email: brett at brettdidonato dot com twitter: @brettdidonato
  • 2. Agenda 1. Configure AWS Simple Email Services (SES) 2. Configure AWS Elastic Cloud Compute (EC2) 3. Creating an Email System a. Sending Emails With Python & Django b. Tracking Opens & Unsubscribes c. Open Email In Browser d. Scheduling With Cron e. Formatting Emails – Best Practices f. Personalizing The Experience 4. Case Study: Email Reminder System
  • 3. Configure AWS SES 1. Test Settings – Verify Individual Email Addresses 2. Production Settings – Verify Domain 3. DNS – AWS Route 53
  • 4. Configure AWS EC2 1. Launch an instance 2. Configure Apache, Python, Python Libraries, Django, MongoDB 3. Start Apache & MongoDB 4. 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 1. Install django-ses 2. 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 1. Embed image in email body with URL pointing towards Django server address: <img src=“mywebsite.com/email_img/campaign/identifier” /> 2. urls.py: (r'^email_img/(?P<campaign>.*)/(?P<identifier>.*)$', email_img), 3. 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 1. Embed link in email body with URL pointing towards Django server address: <a href=http://mywebsite.com/unsubscribe/userid>Unsubscribe</a> 2. urls.py: (r'^unsubscribe/(?P<campaign>.*)/(?P<userid>.*)$', email_tracking_file), 3. 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 1. 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> 2. Urls.py: (r'^email_in_browser/(?P<campaign>.*)/(?P<userid>.*)$', email_tracking_file), 3. 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 1. Open cron table: crontab –e 2. Run job daily at midnight
 0 0 * * * python /directory/for/email_script.py Log file: /var/log/cron Note: consider using a CRON alternative like Celery for more advanced use cases
  • 11. Formatting Emails – Best Practices 1. No JavaScript 2. GIF or JPG Images 3. HTML Tables 4. Inline CSS 5. Max width ~600px 6. Avoid “spammy” words (in subject especially) 7. Test with major email providers: Gmail, Yahoo!, Outlook, Hotmail/Outlook.com, AOL
  • 12. Personalizing the Experience 1. Build something that adds value 2. Give the user control 3. Personalized subject & body: 1. Name 2. Age 3. Sex 4. Browsing history 5. Shopping history 6. 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 1. Users log in to website and configure important life events 2. Event details stored in MongoDB 3. Cron job scheduled once per day against reminder events for current day 4. Database logging and events updated 5. Emails sent with personalized email subject and body 6. Track opens and provide “view in browser” link 7. 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 Thanks! Brett DiDonato email: brett at brettdidonato dot com twitter: @brettdidonato