Skip to content

Instantly share code, notes, and snippets.

@qpfiffer
Last active December 18, 2015 23:18
Show Gist options
  • Save qpfiffer/5860178 to your computer and use it in GitHub Desktop.
Save qpfiffer/5860178 to your computer and use it in GitHub Desktop.
Scrip to do some fancy snippet emailin'
from datetime import date
from django.core.mail import EmailMessage, EmailMultiAlternatives
from django.template import Context, loader
snippet = Snippet.objects.get(slug='azure-incentive-program-rollout')
codes = { date(2013,6,25): ["Q3", "K4", "M1", "L1", "G3", "J3", "O1", "J7"]
, date(2013,6,26): ["K6", "K5", "G4", "N2", "K1", "N1", "J6", "I2", "D1", "F2", "C1"]
, date(2013,6,27): ["L2", "J4", "D3", "P1", "B1", "P2", "K2", "J5", "G1", "C2"]
, date(2013,6,28): ["K3", "Q1", "Q2", "I2", "L3", "D2", "G2", "F1", "J1", "J2", "C3"]
}
today = date.today()
todays_codes = codes[today]
print "I want to send emails to " + str(todays_codes)
routes = Route.objects.filter(code__in=todays_codes)
jayes_email = "test@test.com"
for route in routes:
for drop_point in route.drop_points.all():
account = drop_point.primary_contact
if drop_point.active is False:
continue
if account is None:
continue
context = Context({
'drop_point': drop_point,
})
email_render_txt = snippet.render(context=context,
text=True)
email_render_html = snippet.render(context=context)
email = EmailMultiAlternatives(snippet.subject,
email_render_txt,
"Azure Standard <info@azurestandard.com>",
[account.email],
headers={'reply-to': jayes_email})
email.attach_alternative(email_render_html, "text/html")
#email.send(fail_silently=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment