This library allows you to quickly and easily send emails through SendGrid using Python.
Warning! This library was recently updated to bring it up to date with all of our other libraries. It behaves completely different from the previous release. Also, SMTP has been deprecated in support for the Web API.
pip install sendgrid
//or
easy_install sendgrid
import sendgrid
import os
sg = sendgrid.SendGridClient(os.getenv('SG_USER'), os.getenv('SG_PWD'))
message = sendgrid.Mail()
message.add_to('John Doe <[email protected]>')
message.set_subject('Example')
message.set_html('Body?')
message.set_text('Body?')
message.set_from('Doe John <[email protected]>')
sg.send(message)
message = sendgrid.Mail()
message.add_to('[email protected]')
# or
message.add_to('Example Dude <[email protected]>')
message = sendgrid.Mail()
message.add_bcc('[email protected]')
message = sendgrid.Mail()
message.set_subject('New email')
message = sendgrid.Mail()
message.set_text('Body')
# or
message.set_html('<html><body>Stuff, you know?</body></html>')
message = sendgrid.Mail()
message.set_from('[email protected]')
message = sendgrid.Mail()
message.add_attachment('./stuff.txt')
# or
message.add_attachment_stream('filename', 'somerandomcontentyouwant')
SendGrid's X-SMTPAPI
If you wish to use the X-SMTPAPI on your own app, you can use the SMTPAPI Python library.
There are implementations for setter methods too.
message = sendgrid.Mail()
message.add_substitution("key", "value")
message = sendgrid.Mail()
message.add_section("section", "value")
message = sendgrid.Mail()
message.add_category("category")
message = sendgrid.Mail()
message.add_unique_arg("key", "value")
message = sendgrid.Mail()
message.add_filter("filter", "setting", "value")
- Add support for CID
python test/__init__.py