Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crisward/mailer
Simple Email Sending Client for Mailgun & Sendgrid services in crystal
https://github.com/crisward/mailer
crystal email mailgun sendgrid
Last synced: 11 days ago
JSON representation
Simple Email Sending Client for Mailgun & Sendgrid services in crystal
- Host: GitHub
- URL: https://github.com/crisward/mailer
- Owner: crisward
- License: mit
- Created: 2017-09-26T18:50:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-11-06T10:24:10.000Z (over 4 years ago)
- Last Synced: 2024-04-17T04:01:51.283Z (10 months ago)
- Topics: crystal, email, mailgun, sendgrid
- Language: Crystal
- Homepage:
- Size: 51.8 KB
- Stars: 15
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mailer
This project aims to provide a common api for popular email providers. It currently supports
* Mailgun
* SendgridI also plan to add a wrapper for [SMTP](https://github.com/arcage/crystal-email)
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
mailer:
github: crisward/mailer
```## Usage
```crystal
require "mailer"Mailer.config(provider: Mailer::Mailgun.new(key: ENV["MAILGUN_KEY"], domain: ENV["MAILGUN_DOMAIN"]))
email = Mailer::Message.new
email.to("[email protected]","their_name")
email.from = "[email protected]"
email.subject = "Hello"
email.text = "Some plain text messaeg"
email.html = "Some html message
"
email.attachment = Mailer::Attachment.new(filename: "test.pdf" , path: "./spec/test.pdf")
email.inline = Mailer::Attachment.new(filename: "logo.jpg" , path: "./spec/test.png")
email.send
```To use sendgrid, swap the first line to
```
Mailer.config(provider: Mailer::Sendgrid.new(key: "your sendgrid api key"))
```## Testing Your App
While testing your app, you probably won't want to send real emails.
You can use the built in Mock provider for this.```crystal
# eg for kemal
if ENV["KEMAL_ENV"]? != "test"
Mailer.config(provider: Mailer::Mailgun.new(key: ENV["MAILGUN_KEY"], domain: ENV["MAILGUN_DOMAIN"]))
else
Mailer.config(provider:Mailer::Mock.new())
end
```## Development
Running tests
```bash
# mock
crystal spec#mailgun
MAILGUN_KEY="your-api-key" MAILGUN_DOMAIN="mailgun-domain" EMAIL="[email protected]" crystal spec#sendgrid
SENDGRID_KEY="your-api-key" EMAIL="[email protected]" crystal spec```
## Todo
This library isn't full baked. It works, but there are some thing which need adding
- [ ] Error Handling
- [ ] Logging
- [ ] Adding SMTP option## Contributing
1. Fork it ( https://github.com/crisward/mailer/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request## Contributors
- [Cris Ward](https://github.com/crisward) - creator, maintainer