SendGrid library for Python
Project description
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.
Install
pip install sendgrid
# or
easy_install sendgrid
Example
import sendgrid
sg = sendgrid.SendGridClient('YOUR_SENDGRID_USERNAME', 'YOUR_SENDGRID_PASSWORD')
message = sendgrid.Mail()
message.add_to('John Doe <john@email.com>')
message.set_subject('Example')
message.set_html('Body')
message.set_text('Body')
message.set_from('Doe John <doe@email.com>')
status, msg = sg.send(message)
#or
message = sendgrid.Mail(to='john@email.com', subject='Example', html='Body', text='Body', from_email='doe@email.com')
status, msg = sg.send(message)
Adding Recipients
message = sendgrid.Mail()
message.add_to('example@email.com')
# or
message.add_to('Example Dude <example@email.com>')
# or
message.add_to(['Example Dude <example@email.com>', 'john@email.com'])
Adding BCC Recipients
message = sendgrid.Mail()
message.add_bcc('example@email.com')
# or
message.add_bcc(['Example Dude <example@email.com>', 'john@email.com'])
Setting the Subject
message = sendgrid.Mail()
message.set_subject('Example')
Set Text or HTML
message = sendgrid.Mail()
message.set_text('Body')
# or
message.set_html('<html><body>Stuff, you know?</body></html>')
Set From
message = sendgrid.Mail()
message.set_from('example@email.com')
Set File Attachments
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.
Substitution
message = sendgrid.Mail()
message.add_substitution("key", "value")
Section
message = sendgrid.Mail()
message.add_section("section", "value")
Category
message = sendgrid.Mail()
message.add_category("category")
Unique Arguments
message = sendgrid.Mail()
message.add_unique_arg("key", "value")
Filter
message = sendgrid.Mail()
message.add_filter("filter", "setting", "value")
TODO:
Add support for CID
Tests
python test/__init__.py
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sendgrid-0.3.0.tar.gz
(4.6 kB
view hashes)
Built Distribution
Close
Hashes for sendgrid-0.3.0.macosx-10.9-intel.exe
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bc6e1dccb05690974ede633c8409c87ae6f40cddc3f158f84bdaa9b871149ae |
|
MD5 | 5e8703d1d4335c2a118f7017bde98d09 |
|
BLAKE2b-256 | 06ee83f7a077df5d2e1a75ceae823e118f7b82ae070ef6058c1ce82d6bedcd72 |