Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
/ mailopen Public archive

Buffalo sender that opens emails in browser.

License

Notifications You must be signed in to change notification settings

paganotoni/mailopen

Repository files navigation

Important: I built an alternative to mailopen: Meilo. Meilo does not rely on Buffalo or its dependencies. It works as an SMTP server that can be replaced in production with credentials. I've found using SMTP is better in the long run as one can switch between providers without much issues.

Build Status

Mailopen

Mailopen is a buffalo mailer that allows to see sent emails in the browser instead of sending these using SMTP or other sender used in production environments.

Usage

Mailopen is only intended for development purposes, the way you use it is by simply initializing your mailer to be a mailopen instance instead of your regular sender, p.e:

import (
    ...
    "github.com/gobuffalo/buffalo/mail"
    sendgrid "github.com/paganotoni/sendgrid-sender"
    ...
)

//Sender allows us to send emails
var Sender mail.Sender

func init() {
    sgSender := sendgrid.NewSendgridSender(envy.Get("SENDGRID_API_KEY", ""))
    Sender = mailopen.Wrap(sgSender)
}

Internally Wrap function returns mailopen.FileSender instance only if GO_ENV is development, otherwise it will return passed sender.

You can always write it yourself in case your conditions to switch sender are not only to be in the development environment.

import (
    ...
    "github.com/gobuffalo/buffalo/mail"
    sendgrid "github.com/paganotoni/sendgrid-sender"
    ...
)

func init() {
    if envy.Get("GO_ENV", "development") == "development" {
        Sender = mailopen.WithOptions(mailopen.Only("text/html"))
        
		return
    }

    Sender = sendgrid.NewSendgridSender(envy.Get("SENDGRID_API_KEY", ""))
}

Then you will use your Sender instance as usual by calling Sender.Send(m) with the variant that in development it will open your emails in the browser.

By default, mailopen will save the emails and attachments in a temporary directory. You can customize this by passing options to the mailopen.WithOptions or setting the MAILOPEN_DIR env variable in your machine.

Options

You can pass options to the mailopen.WithOptions function to customize the way it work.

  • Only allows you to specify which content types you want to open in the browser, p.e: mailopen.Only("text/html").

  • Directory allows you to specify the directory where the emails and attachments will be saved, p.e: mailopen.Directory("/tmp").