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 ReplyTo
message.sendgrid.Mail()
message.set_replyto('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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sendgrid-0.3.6.tar.gz.
File metadata
- Download URL: sendgrid-0.3.6.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d7f43e72811725e0d37dd7ccc6b771b32a3078114bb90e4ce469d533ae9c47b
|
|
| MD5 |
d00e72871c4bc034f42a3067bc20dfe1
|
|
| BLAKE2b-256 |
24e8c4c382e0e82f26fbc8d41d2c5000c7422943230d761a7c8d626754508c1e
|
File details
Details for the file sendgrid-0.3.6.macosx-10.9-intel.exe.
File metadata
- Download URL: sendgrid-0.3.6.macosx-10.9-intel.exe
- Upload date:
- Size: 71.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d87f771e800c4bfe4a9c30e2f32135c93b8ce01c3485027f97564dcd8259c1c9
|
|
| MD5 |
5bf7c24fd1e581cfd6570afe7c67b77e
|
|
| BLAKE2b-256 |
2092be17d7d80b02b52ae3c7766b077946c43decb9aa7275c3adce62f3f28746
|