Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import sendgrid
  2.  
  3. class Email(object):
  4.  
  5. def __init__(self, api_key):
  6. self.sg = sendgrid.SendGridAPIClient(apikey=api_key)
  7. self.from_name = 'from name'
  8.  
  9. def send(self, to_email, from_email, subj, msg, category, time=-1):
  10. data = {
  11. "personalizations": [
  12. {
  13. "to": [
  14. {
  15. "email": str(to_email)
  16. }
  17. ]
  18. }
  19. ],
  20. "content": [
  21. {
  22. "type": "text/html",
  23. "value": str(msg)
  24. }
  25. ],
  26. "from": {
  27. "email": from_email,
  28. "name": self.from_name
  29. },
  30. "subject": str(subj),
  31. "categories": [category]
  32. }
  33. data['send_at'] = int(time)
  34. response = self.sg.client.mail.send.post(request_body=data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement