Skip to main content

Send messages through SendGrid using SMTP

Project description

PYSGS

This is a small tool designed as part of learning, allows sending SendGrid messages via SMTP

Table of Contents

Installation

pip install pysgs

Setup

import pysgs
service = pysgs.mailer('SENDGRID_API_KEY')

Headers

sender = "user@example.com"
recipient = "anotheruser@example.com"
subject = "This is a Subject!!"
service.headers(sender, recipient, subject)

Sender

There are different ways to set recipent emails.

You can also send a list of recipients

recipients = [
    "User <user@example.com>",
    "Another User <anotheruser@example.com>"
]

Usage

Plain text

service.content('Message from sendgrid')
service.send()

HTML Content

service.content('<h1>Hello World!</h1>', 'html')
service.send()

Attachment

service.content('/path/to/file/audio.mp3', is_attach=True)
service.send()

Example

import pysgs
from pysgs.exceptions import SGSError

try:
    """Start connection"""
    service = pysgs.mailer("SENDGRID_API_KEY")

    """Set message headers"""
    sender = "user@example.com"
    recipient = "anotheruser@example.com"
    subject = "This is a Subject!!"
    service.headers(sender, recipient, subject)

    """Set content"""
    service.content('Message from sendgrid')
    service.content('<h1>Hello World!</h1>', 'html')
    service.content('/path/to/file/audio.mp3', is_attach=True)

    """Send message"""
    service.send()

    """Finish service"""
    service.close()

except SGSError as e:
    print('There was an error: ' + str(e))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pysgs, version 1.2
Filename, size File type Python version Upload date Hashes
Filename, size pysgs-1.2-py3-none-any.whl (5.6 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page