Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ayushgun/easygmail

A lightweight, minimalistic, and synchronous Python package for quickly sending emails via Gmail.
https://github.com/ayushgun/easygmail

Last synced: about 1 month ago
JSON representation

A lightweight, minimalistic, and synchronous Python package for quickly sending emails via Gmail.

Awesome Lists containing this project

README

        

# EasyGmail

## Overview

EasyGmail is a lightweight, minimalistic, and synchronous Python API designed for quick email sending via Gmail.

## Roadmap

The current release is a beta release. By stable release 1.0, the following features are projected to be added:

- [ ] Unit testing
- [ ] Static Site Documentation
- [ ] File Attachments
- [ ] HTML Emails
- [ ] Variadic Recipients

## Getting Started

### Installation

```
pip install git+https://github.com/ayushgun/easygmail
```

### Prerequisites

Before using EasyGmail, ensure you have an [app password](https://support.google.com/mail/answer/185833?hl=en#app-passwords) for Gmail. Do **not** use your regular account password.

### Quick Start Example

```python
from easygmail import Client, EmailBuilder

client = Client("

@gmail.com", "")

msg = EmailBuilder(
receiver="@domain.com", subject="", body=""
).build()

client.send(msg)
```

### Client Initialization

You can instantiate a `Client` object in two ways:

1. **Direct Credentials**:
Provide email address and app password directly as arguments.

```python
from easygmail import Client

client = Client("

@gmail.com", "")
```

2. **Environment File**:
Use a `.env` file to store credentials.

```python
from easygmail import Client

client = Client(env_file=".env")
```

Your `.env` file should contain:

```bash
EMAIL_ADDRESS="

@gmail.com"
PASSWORD=""
```

### Creating Email Messages

Create `EmailMessage` objects using one of the following methods:

1. **EmailBuilder Constructor**:

```python
from easygmail import EmailBuilder

msg = EmailBuilder(
receiver="@domain.com", subject="", body=""
).build()
```

2. **EmailBuilder Factory Interface**:

```python
from easygmail import EmailBuilder

msg = (
EmailBuilder()
.set_receiver("@domain.com")
.set_subject("")
.set_body("")
).build()
```

3. **Directly Using `EmailMessage`**:

```python
from email.message import EmailMessage

msg = EmailMessage()
msg["To"] = "@domain.com"
msg["Subject"] = ""
msg.set_content("")
```