Skip to main content

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>')
sg.send(message)

#or

message = sendgrid.Mail(to='john@email.com', subject='Example', html='Body', text='Body', from_email='doe@email.com')
sg.send(message)

Adding Recipients

message = sendgrid.Mail()
message.add_to('example@email.com')
# or
message.add_to('Example Dude <example@email.com>')

Adding BCC Recipients

message = sendgrid.Mail()
message.add_bcc('example@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.2.6.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sendgrid-0.2.6.macosx-10.9-intel.exe (70.6 kB view details)

Uploaded Source

File details

Details for the file sendgrid-0.2.6.tar.gz.

File metadata

  • Download URL: sendgrid-0.2.6.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sendgrid-0.2.6.tar.gz
Algorithm Hash digest
SHA256 0afd68c6bb05652bbf2be97f1cd16e94edc3c526e0a0b672dabb600b7ac633c6
MD5 c9593769f6a0b840b150e6a07cc4683d
BLAKE2b-256 543bb7101ee576780746eaf78fec59b1815ba39d2c7006b2fb2e716ec2e706c1

See more details on using hashes here.

File details

Details for the file sendgrid-0.2.6.macosx-10.9-intel.exe.

File metadata

File hashes

Hashes for sendgrid-0.2.6.macosx-10.9-intel.exe
Algorithm Hash digest
SHA256 1fe1a2e9722b798e5122010ed78c3acc5bb8c7a217bce40f36dd22fd39c90cec
MD5 45843537b2b8041f0ece18cec29f3ea4
BLAKE2b-256 c48c13a6402dce6e34ec7c99b0e891cdd5a4677ac26b100fa65d725228f83e69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page