easy-email-builder


Nameeasy-email-builder JSON
Version 1.0.2 PyPI version JSON
download
home_page
SummarySimple interface for sending emails with the builder design pattern with different services.
upload_time2023-07-25 19:43:53
maintainer
docs_urlNone
authorRyan Schreiber
requires_python>=3.0
license
keywords email emails builder smtp gmail ses aws
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # email-builder
This is a module to make it simple to send emails. The code follows the builder design pattern and the 
email code is completely separated from the client used to actually send the email, making it easy to switch to
a new client if we ever need to move away from SES for whatever reason.

## Sample Usage

#### Install
```
pip install easy-email-builder
```

#### Setup

```python
import email_builder
```

#### Send an email from Gmail

```python
# builder syntax
# when using gmail, you need an "App Password". follow this link if you need help creating that:
# https://www.lifewire.com/get-a-password-to-access-gmail-by-pop-imap-2-1171882

import email_builder

client = email_builder.clients.Gmail(password="<gmail APP password>")
email = (
  email_builder.Email()
    .sender("your.email@gmail.com")
    .to("someones.email@gmail.com")
    .cc("copy.email@gmail.com")
    .bcc("another.copy.email@gmail.com")
    .subject("test email sent from my python lib")
    .text("hello world")
)
email.send(client)
```

#### Send an email Amazon SES with just some html as the body

```python
# builder syntax 
import email_builder

# this SES class accepts a boto3 session if you want to customize the setup
client = email_builder.clients.SES()
email = (
  email_builder.Email()
    .sender("my.email@company.com")
    .to("recipient.1@company.com")
    .to("recipient.2@company.com")
    .subject("test email sent from my python lib")
    .html("<h1> hello world </h1>")
)
email.send(email_builder.clients.SES())
```

#### Send an email with attachments

```python
# note that the contents of the attachments can be either string or bytestring 
import email_builder

with open("report.csv", "rb") as f:
  data = f.read()

client = email_builder.clients.SES()
email = (
  email_builder.Email()
    .sender("my.email@company.com")
    .to("recipient.1@company.com")
    .to("recipient.2@company.com")
    .subject("test email sent from my python lib")
    .html("<h1> hello world </h1>")
    .attachment(email_builder.Attachment("report.csv", data))
    .attachment(email_builder.Attachment("test2.json", """{"key": "value"}"""))
).send(email_builder.clients.SES())
```

## Email Options

```python
import email_builder

with open("report.csv", "rb") as f:
  data = f.read()

# --- client types are SES or Gmail --- #
# Amazon SES that can accept a session object as needed
client = email_builder.clients.SES()
# or
import boto3
session = boto3.Session(region="us-west-2", etc)
client = email_builder.clients.SES(session)

# Gmail that accepts a password and options to configure port/url if needed
client = email_builder.clients.SES(password="<password>")


# --- email options --- #
email = (
  email_builder.Email()

    # sender(sender:str) -> only one sender allowed, no chaining allowed on sender
    .sender("my.email@company.com")

    # to(*recipients:str) -> you can add as many as you want here, and chain to()
    #                        calls successively
    .to("recipient.1@company.com")
    .to("recipient.2@company.com")

    # cc(*recipients:str) -> you can add as many as you want here, and chain to()
    #                        calls successively
    .cc("recipient.1@company.com")
    .cc("recipient.2@company.com")

    # bcc(*recipients:str) -> you can add as many as you want here, and chain to()
    #                        calls successively
    .bcc("recipient.1@company.com")
    .bcc("recipient.2@company.com")

    # subject(subject:str) -> only one subject line allowed
    .subject("test email sent from my python lib")

    # --- EMAIL BODY --- #
    # you need to choose between either html or text, can't use both

    # html(body:str) -> renders the given html in the email body, no chaining
    .html("<h1> hello world </h1>")

    # test(body:str) -> adds the given text to the email body as plain text
    .text("hello world")

    # attachment(attachment:email_builder.Attchment) -> chain as many of these as you want
    .attachment(email_builder.Attachment("report.csv", data))
    .attachment(email_builder.Attachment("test2.json", """{"key": "value"}"""))

)

# result contains a dictionary with status in the body
result = email.send(client)
print(result)
```

Success result:
```python
{
	"status": "passed",
	"error": None
}
```

Failure result:
```python
{
	"status": "failed",
	"error": Exception(...)
}
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "easy-email-builder",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.0",
    "maintainer_email": "",
    "keywords": "email emails builder smtp gmail ses aws",
    "author": "Ryan Schreiber",
    "author_email": "ryanschreiber86@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f7/b0/3124b24ca24216252cd72c56f8289048657eadaf95e2cd9ffb768a86a1cf/easy-email-builder-1.0.2.tar.gz",
    "platform": null,
    "description": "# email-builder\nThis is a module to make it simple to send emails. The code follows the builder design pattern and the \nemail code is completely separated from the client used to actually send the email, making it easy to switch to\na new client if we ever need to move away from SES for whatever reason.\n\n## Sample Usage\n\n#### Install\n```\npip install easy-email-builder\n```\n\n#### Setup\n\n```python\nimport email_builder\n```\n\n#### Send an email from Gmail\n\n```python\n# builder syntax\n# when using gmail, you need an \"App Password\". follow this link if you need help creating that:\n# https://www.lifewire.com/get-a-password-to-access-gmail-by-pop-imap-2-1171882\n\nimport email_builder\n\nclient = email_builder.clients.Gmail(password=\"<gmail APP password>\")\nemail = (\n  email_builder.Email()\n    .sender(\"your.email@gmail.com\")\n    .to(\"someones.email@gmail.com\")\n    .cc(\"copy.email@gmail.com\")\n    .bcc(\"another.copy.email@gmail.com\")\n    .subject(\"test email sent from my python lib\")\n    .text(\"hello world\")\n)\nemail.send(client)\n```\n\n#### Send an email Amazon SES with just some html as the body\n\n```python\n# builder syntax \nimport email_builder\n\n# this SES class accepts a boto3 session if you want to customize the setup\nclient = email_builder.clients.SES()\nemail = (\n  email_builder.Email()\n    .sender(\"my.email@company.com\")\n    .to(\"recipient.1@company.com\")\n    .to(\"recipient.2@company.com\")\n    .subject(\"test email sent from my python lib\")\n    .html(\"<h1> hello world </h1>\")\n)\nemail.send(email_builder.clients.SES())\n```\n\n#### Send an email with attachments\n\n```python\n# note that the contents of the attachments can be either string or bytestring \nimport email_builder\n\nwith open(\"report.csv\", \"rb\") as f:\n  data = f.read()\n\nclient = email_builder.clients.SES()\nemail = (\n  email_builder.Email()\n    .sender(\"my.email@company.com\")\n    .to(\"recipient.1@company.com\")\n    .to(\"recipient.2@company.com\")\n    .subject(\"test email sent from my python lib\")\n    .html(\"<h1> hello world </h1>\")\n    .attachment(email_builder.Attachment(\"report.csv\", data))\n    .attachment(email_builder.Attachment(\"test2.json\", \"\"\"{\"key\": \"value\"}\"\"\"))\n).send(email_builder.clients.SES())\n```\n\n## Email Options\n\n```python\nimport email_builder\n\nwith open(\"report.csv\", \"rb\") as f:\n  data = f.read()\n\n# --- client types are SES or Gmail --- #\n# Amazon SES that can accept a session object as needed\nclient = email_builder.clients.SES()\n# or\nimport boto3\nsession = boto3.Session(region=\"us-west-2\", etc)\nclient = email_builder.clients.SES(session)\n\n# Gmail that accepts a password and options to configure port/url if needed\nclient = email_builder.clients.SES(password=\"<password>\")\n\n\n# --- email options --- #\nemail = (\n  email_builder.Email()\n\n    # sender(sender:str) -> only one sender allowed, no chaining allowed on sender\n    .sender(\"my.email@company.com\")\n\n    # to(*recipients:str) -> you can add as many as you want here, and chain to()\n    #                        calls successively\n    .to(\"recipient.1@company.com\")\n    .to(\"recipient.2@company.com\")\n\n    # cc(*recipients:str) -> you can add as many as you want here, and chain to()\n    #                        calls successively\n    .cc(\"recipient.1@company.com\")\n    .cc(\"recipient.2@company.com\")\n\n    # bcc(*recipients:str) -> you can add as many as you want here, and chain to()\n    #                        calls successively\n    .bcc(\"recipient.1@company.com\")\n    .bcc(\"recipient.2@company.com\")\n\n    # subject(subject:str) -> only one subject line allowed\n    .subject(\"test email sent from my python lib\")\n\n    # --- EMAIL BODY --- #\n    # you need to choose between either html or text, can't use both\n\n    # html(body:str) -> renders the given html in the email body, no chaining\n    .html(\"<h1> hello world </h1>\")\n\n    # test(body:str) -> adds the given text to the email body as plain text\n    .text(\"hello world\")\n\n    # attachment(attachment:email_builder.Attchment) -> chain as many of these as you want\n    .attachment(email_builder.Attachment(\"report.csv\", data))\n    .attachment(email_builder.Attachment(\"test2.json\", \"\"\"{\"key\": \"value\"}\"\"\"))\n\n)\n\n# result contains a dictionary with status in the body\nresult = email.send(client)\nprint(result)\n```\n\nSuccess result:\n```python\n{\n\t\"status\": \"passed\",\n\t\"error\": None\n}\n```\n\nFailure result:\n```python\n{\n\t\"status\": \"failed\",\n\t\"error\": Exception(...)\n}\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Simple interface for sending emails with the builder design pattern with different services.",
    "version": "1.0.2",
    "project_urls": {
        "Documentation": "https://github.com/ryan-schreiber/email-builder/",
        "Source": "https://github.com/ryan-schreiber/email-builder/",
        "Tracker": "https://github.com/ryan-schreiber/email-builder/issues"
    },
    "split_keywords": [
        "email",
        "emails",
        "builder",
        "smtp",
        "gmail",
        "ses",
        "aws"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "00da9cb3e6095da1e2dc8aa8bb0a7700261934c7820572c41f7a0c9e12d42628",
                "md5": "c92e76a63723a518472a7912c1a09312",
                "sha256": "43715d63cdfdba0906d038e9988a3160f8eb9cc32c6d334f1252b0e7083b2446"
            },
            "downloads": -1,
            "filename": "easy_email_builder-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c92e76a63723a518472a7912c1a09312",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.0",
            "size": 4084,
            "upload_time": "2023-07-25T19:43:52",
            "upload_time_iso_8601": "2023-07-25T19:43:52.431635Z",
            "url": "https://files.pythonhosted.org/packages/00/da/9cb3e6095da1e2dc8aa8bb0a7700261934c7820572c41f7a0c9e12d42628/easy_email_builder-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7b03124b24ca24216252cd72c56f8289048657eadaf95e2cd9ffb768a86a1cf",
                "md5": "80e6ad9eb08503d376c8245155d5a90a",
                "sha256": "142820050a571c63e1b8ae4335eda5d04502065df5b2d232f0faf1dddf2c3961"
            },
            "downloads": -1,
            "filename": "easy-email-builder-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "80e6ad9eb08503d376c8245155d5a90a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.0",
            "size": 3811,
            "upload_time": "2023-07-25T19:43:53",
            "upload_time_iso_8601": "2023-07-25T19:43:53.396845Z",
            "url": "https://files.pythonhosted.org/packages/f7/b0/3124b24ca24216252cd72c56f8289048657eadaf95e2cd9ffb768a86a1cf/easy-email-builder-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-25 19:43:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ryan-schreiber",
    "github_project": "email-builder",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "easy-email-builder"
}
        
Elapsed time: 0.09786s