Description
A very easy interface for sending simple text based emails.
Installation
gem install ez-email
Adding the trusted cert
gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/ez-email/main/certs/djberg96_pub.pem)
Synopsis
require 'ez-email'
# Simple email
EZ::Email.deliver(
:to => 'your_friend@hotstuff.com',
:from => 'you@blah.com',
:subject => 'Hello',
:body => 'How are you?'
)
# Email with attachments
EZ::Email.deliver(
:to => 'your_friend@hotstuff.com',
:from => 'you@blah.com',
:subject => 'Files attached',
:body => 'Please find the attached files.',
:attachments => ['/path/to/file1.pdf', '/path/to/file2.txt']
)
Rationale
When I originally created this library the existing list of email handling libraries were either not designed for sending email, were extremely cumbersome, had lousy interfaces, or were no longer maintained.
I just wanted to send a flippin' email! This library scratched that itch. Hopefully you will find its simplicity useful, too.
Features
- Simple interface for sending text emails
- Support for multiple recipients
- File attachments support
- Automatic MIME type detection for attachments
- Minimal dependencies
API
The library supports these options:
-
:to
- Email address(es) of recipient(s). Can be a string or array. (Required) -
:from
- Email address of sender. Defaults to user@hostname if not specified. -
:subject
- Subject line of the email. (Required) -
:body
- Body text of the email. (Required) -
:attachments
- Array of file paths to attach. (Optional)
All file attachments are automatically base64 encoded and sent with appropriate MIME types.
Local Testing
To run the specs you will need a mail server running locally. If you do not already have a mail server running on port 1025 then install docker and run the following command:
docker compose run mailhog
Once the mailhog docker image is installed and a container is running, you can run the specs. You can also view the emails that were generated by pointing your web browser at http://localhost:8025 after running the specs for visual verification.
Bugs
None that I'm aware of. Please log any bug reports on the project page at
https://github.com/djberg96/ez-email.
See Also
The "pony" gem at https://github.com/benprew/pony.
License
Apache-2.0
Copyright
(C) 2009-2023, Daniel J. Berger, All Rights Reserved
Author
Daniel Berger