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

https://github.com/trikko/postino

A simple and secure SMTP library for D with support for MIME email, HTML mail with embedded files and attachments
https://github.com/trikko/postino

d dlang email email-sender mail smtp

Last synced: 5 months ago
JSON representation

A simple and secure SMTP library for D with support for MIME email, HTML mail with embedded files and attachments

Awesome Lists containing this project

README

          

# postino

*(italian word for Β«postmanΒ»)*

A simple and secure MIME email library for D with support for HTML, attachments, and embedded files.

## Features

- πŸš€ **Simple API** - Send emails with just a few lines of code
- πŸ“§ **MIME Support** - Full multipart/alternative and multipart/related support
- πŸ“Ž **Attachments** - Support for file attachments and embedded images
- 🎨 **HTML Emails** - Send rich HTML emails with embedded images

## Quick Start

### Installation

Add postino to your `dub.json` or use DUB directly:

```bash
dub add postino
```

### Basic Usage

```d
import postino;

void main()
{
auto email = new Email();

// Method chaining
email
.setFrom("sender@example.com", "John Doe")
.addTo("recipient@example.com", "Jane Smith")
.setSubject("Hello from postino!")
.setPlainTextBody("Hello, this is a plain text email.")
.setHtmlBody("

Hello!

This is an HTML email.

")
.send("smtps://smtp.example.com:465", "username", "password");
}
```

## Advanced Examples

### HTML Email with Embedded Image

```d
new Email()
.setFrom("newsletter@example.com", "Company Newsletter")
.addTo("customer@example.com", "Valued Customer")
.setSubject("Monthly Newsletter")
.setHtmlBody(`


Welcome to our Newsletter!


Check out our latest product:


New Product

Best regards,
The Team




`)
.addEmbeddedFile("/path/to/product.png", "product-image")
.send("smtps://smtp.example.com:465", "username", "password");
```

### Multiple Recipients with Attachments

```d
new Email()
.setFrom("reports@example.com", "Automated Reports")
.addTo("manager@example.com", "Project Manager")
.addTo("team@example.com", "Development Team")
.addCc("archive@example.com")
.setSubject("Weekly Report")
.setPlainTextBody("Please find the weekly report attached.")
.addAttachment("/path/to/report.pdf")
.addAttachment("/path/to/data.xlsx")
.send("smtp://internal-smtp.example.com:25");
```

### Newsletter with Multiple Features

```d
new Email()
.setFrom("marketing@example.com", "Marketing Team")
.addTo("subscriber1@example.com", "John Doe")
.addTo("subscriber2@example.com", "Jane Smith")
.addBcc("analytics@example.com")
.setReplyTo("support@example.com", "Customer Support")
.setSubject("πŸŽ‰ Special Offer Inside!")
.setPlainTextBody("Visit our website for a special 20% discount!")
.setHtmlBody(`


πŸŽ‰ Special Offer!


Get 20% off your next purchase!


Special Offer

Shop Now




`)
.addEmbeddedFile("/path/to/banner.jpg", "banner")
.addAttachment("/path/to/catalog.pdf")
.send("smtps://smtp.example.com:587", "marketing@example.com", "password");
```

## API Reference

### Email Configuration (Chainable)

| Method | Description |
|--------|-------------|
| `setFrom(address, name?)` | Set sender email and optional display name |
| `addTo(address, name?)` | Add recipient to "To" field |
| `addCc(address, name?)` | Add recipient to "Cc" field |
| `addBcc(address, name?)` | Add recipient to "Bcc" field |
| `setReplyTo(address, name?)` | Set reply-to address |
| `setSubject(subject)` | Set email subject |

### Content (Chainable)

| Method | Description |
|--------|-------------|
| `setPlainTextBody(text)` | Set plain text content |
| `setHtmlBody(html)` | Set HTML content |
| `addAttachment(path, mimeType?)` | Add file attachment |
| `addEmbeddedFile(path, cid, mimeType?)` | Add embedded file for HTML |

### Sending and saving

| Method | Description |
|--------|-------------|
| `send(smtpUrl, username?, password?)` | Send email via SMTP |
| `save(path)` | Save email as a .eml file |

## SMTP Configuration

postino supports various SMTP configurations:

```d
// Gmail with app password
email.send("smtps://smtp.gail.com:465", "user@gmail.com", "app-password");

// Outlook/Hotmail
email.send("smtps://smtp-mail.outlook.com:587", "user@outlook.com", "password");

// Local SMTP server (no auth)
email.send("smtp://localhost:25");

// Custom SMTP with TLS
email.send("smtps://mail.example.com:465", "user", "pass");
```

## License

MIT License - see [LICENSE](LICENSE) file for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.