Created
April 3, 2017 19:35
-
-
Save LiYChristopher/46fe018ad91e86a242aae058c97df4b3 to your computer and use it in GitHub Desktop.
Pseudo-code for Sending Attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Pseudo-code example of sending an attachment via SendGrid's API lib. This assumes that | |
you're using one of our coding libraries with helper methods (though this is more or less a Python library example) | |
''' | |
import sendgrid | |
from sendgrid.helpers.mail import * | |
import datetime | |
import base64 | |
mail = Mail() | |
attachment = Attachment() | |
with open(stats_file, 'rb') as data: # you must read the file in binary | |
attachment.set_content(base64.b64encode(data.read()).decode()) # Encode data in base-64 | |
attachment.set_type('image/<file_extension>') # jpg, tiff etc. | |
attachment.set_filename('name_of_file') | |
attachment.set_disposition("attachment") | |
attachment.set_content_id("<arbitrary_value>") | |
mail.add_attachment(attachment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment