postino 0.1.4
A simple and secure SMTP library for D with support for MIME email, HTML mail with embedded files and attachments
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
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:
dub add postino
Basic Usage
import postino;
void main()
{
auto email = new Email();
// Method chaining
email
.setFrom("[email protected]", "John Doe")
.addTo("[email protected]", "Jane Smith")
.setSubject("Hello from postino!")
.setPlainTextBody("Hello, this is a plain text email.")
.setHtmlBody("<h1>Hello!</h1><p>This is an <b>HTML</b> email.</p>")
.send("smtps://smtp.example.com:465", "username", "password");
}
Advanced Examples
HTML Email with Embedded Image
new Email()
.setFrom("[email protected]", "Company Newsletter")
.addTo("[email protected]", "Valued Customer")
.setSubject("Monthly Newsletter")
.setHtmlBody(`
<html>
<body>
<h1>Welcome to our Newsletter!</h1>
<p>Check out our latest product:</p>
<img src="cid:product-image" alt="New Product" width="300">
<p>Best regards,<br>The Team</p>
</body>
</html>
`)
.addEmbeddedFile("/path/to/product.png", "product-image")
.send("smtps://smtp.example.com:465", "username", "password");
Multiple Recipients with Attachments
new Email()
.setFrom("[email protected]", "Automated Reports")
.addTo("[email protected]", "Project Manager")
.addTo("[email protected]", "Development Team")
.addCc("[email protected]")
.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
new Email()
.setFrom("[email protected]", "Marketing Team")
.addTo("[email protected]", "John Doe")
.addTo("[email protected]", "Jane Smith")
.addBcc("[email protected]")
.setReplyTo("[email protected]", "Customer Support")
.setSubject("๐ Special Offer Inside!")
.setPlainTextBody("Visit our website for a special 20% discount!")
.setHtmlBody(`
<html>
<body style="font-family: Arial, sans-serif;">
<h1>๐ Special Offer!</h1>
<p>Get <strong>20% off</strong> your next purchase!</p>
<img src="cid:banner" alt="Special Offer" style="max-width: 100%;">
<p><a href="https://example.com/offer">Shop Now</a></p>
</body>
</html>
`)
.addEmbeddedFile("/path/to/banner.jpg", "banner")
.addAttachment("/path/to/catalog.pdf")
.send("smtps://smtp.example.com:587", "[email protected]", "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
Method | Description |
---|---|
send(smtpUrl, username?, password?) | Send email via SMTP |
SMTP Configuration
postino supports various SMTP configurations:
// Gmail with app password
email.send("smtps://smtp.gail.com:465", "[email protected]", "app-password");
// Outlook/Hotmail
email.send("smtps://smtp-mail.outlook.com:587", "[email protected]", "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 file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- 0.1.4 released 33 days ago
- trikko/postino
- MIT
- Copyright ยฉ 2025, Andrea Fontana
- Authors:
- Dependencies:
- none
- Versions:
-
0.1.4 2025-May-28 0.1.3 2025-May-28 ~main 2025-May-28 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
3 downloads total
-
- Score:
- 0.2
- Short URL:
- postino.dub.pm