Skip to main content

amazon_sender.py

Project description

ir

amazon_sender.py

To install: pip install ir

Overview

The ir package provides a Python helper class named AmazonSender for sending emails using Amazon's Simple Email Service (SES) through the boto library. This class handles encodings properly and supports sending both text and HTML emails. It is designed to be flexible, allowing users to specify various email parameters such as sender, recipient, and message content.

Features

  • Email Encoding: Proper handling of different encodings ensuring that text and HTML emails are correctly displayed.
  • Multiple Recipients: Ability to send emails to multiple recipients.
  • HTML and Text Emails: Support for both HTML and plain text parts in emails.
  • Customizable Sender and Reply-To: Custom sender and reply-to addresses can be specified.
  • AWS Credentials Management: Automatic fetching of AWS credentials from environment variables if not provided.

Installation

To install the package, use the following pip command:

pip install ir

Usage

Initializing the AmazonSender

You can initialize the AmazonSender object by providing AWS credentials directly or letting the class fetch them from environment variables:

from ir import AmazonSender

# Initialize with direct credentials
amazon_sender = AmazonSender(aws_key='your_aws_access_key', aws_secret='your_aws_secret_key')

# Initialize with environment variables
amazon_sender = AmazonSender()

Sending an Email

To send an email, you can use the send_email method. This method allows you to specify the sender, recipient, subject, and body of the email in both text and HTML formats:

response = amazon_sender.send_email(
    sender='Me <me@example.com>',
    to_addresses=['recipient1@example.com', 'recipient2@example.com'],
    subject='Greetings',
    text='Hello, this is a plain text message.',
    html='<h1>Hello</h1><p>This is an HTML message.</p>'
)

Verifying an Email Address

Before sending an email, you might want to verify the email address using Amazon SES:

verification_status = amazon_sender.verify_email('test@example.com')

Class and Method Documentation

class AmazonSender

A class to send emails using Amazon SES.

__init__(self, to_addresses=None, sender=None, aws_key=None, aws_secret=None)

Constructor to initialize the AmazonSender with optional AWS credentials, sender, and recipient addresses.

  • Parameters:
    • to_addresses: The default recipient address(es). Can be a string or a list of strings.
    • sender: The default sender email address.
    • aws_key: AWS access key.
    • aws_secret: AWS secret key.

send_email(self, subject='', text='', html=None, reply_addresses=None, sender_ascii=None)

Sends an email with the specified subject, text, and/or HTML content.

  • Parameters:
    • subject: Subject of the email.
    • text: Plain text content of the email.
    • html: HTML content of the email.
    • reply_addresses: Email address(es) to which replies should be sent.
    • sender_ascii: ASCII representation of the sender's email address, used in the email header.

verify_email(self, email)

Requests Amazon SES to verify an email address.

  • Parameters:
    • email: The email address to verify.

get_client(self)

Initializes or retrieves the SESConnection client.

License

This project is licensed under the BSD license.

Project details


Download files

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

Source Distribution

ir-0.0.6.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

ir-0.0.6-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file ir-0.0.6.tar.gz.

File metadata

  • Download URL: ir-0.0.6.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for ir-0.0.6.tar.gz
Algorithm Hash digest
SHA256 4cd727aabb816ede6ffcaddb37474cc09f30e8996709b5e5c0625b2adda6a0f6
MD5 270c1752df5a9b0244f9fbf967ed729a
BLAKE2b-256 ad26e1617a3d3acc73b88df7363156dded48f76cd70cc6a7f122072f088e436e

See more details on using hashes here.

File details

Details for the file ir-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: ir-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for ir-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 bda0f9138356479e43727fe43147d6f092367f7b3a1364f52036f6acb73da40f
MD5 9a25de4dfe32e22ea31358b521b46aa7
BLAKE2b-256 eaa62e0aedd3dbc911f57f4a13b1f79700d291c09b948881003dad986e613073

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