Skip to content

Instantly share code, notes, and snippets.

@axeliodiaz
Last active May 27, 2016 15:25
Show Gist options
  • Save axeliodiaz/35dd20d6e946480446afb9ad62f42cbb to your computer and use it in GitHub Desktop.
Save axeliodiaz/35dd20d6e946480446afb9ad62f42cbb to your computer and use it in GitHub Desktop.
import sendgrid
from datetime import datetime
SENDGRID_API_KEY = "S3NGR1D_AP1_K3Y"
TEMPLATE_ID = 't3mpl4t3_1d'
sg = sendgrid.SendGridClient(SENDGRID_API_KEY)
date_time = datetime.now()
sender = "Axel Díaz <correo@example>"
subject = "[AXELIO] Test Sendgrid [{}]".format(date_time)
recipients = ['Axel díaz <correo@example.com>']
body = "This is a body"
template_id = TEMPLATE_ID
args = {
# Basic vars
'to': recipients,
'subject': subject,
'html': body,
'text': body,
'from_email': sender,
}
message = sendgrid.Mail(**args)
message.add_filter('templates', 'template_id', template_id)
message.add_substitution('{{ prueba }}', body)
message.add_substitution('{{ titulo }}', "Prueba en Sendgrid!")
status, msg = sg.send(message)
print(status, msg, date_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment