mailopen

package module
v2.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 14 Imported by: 0

README

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 initialyzing 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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Testing = false

Functions

func Wrap

func Wrap(sender mail.Sender) mail.Sender

Wrap other sender to be used if env is not development

Types

type AttFile

type AttFile struct {
	Path string
	Name string
}

AttFile is a file to be attached to the email

type FileSender

type FileSender struct {
	Open    bool
	TempDir string
	// contains filtered or unexported fields
}

FileSender implements the Sender interface to be used within buffalo mailer generated package.

func New

func New() FileSender

New creates a sender that writes emails into disk

func WithOptions

func WithOptions(options ...Option) FileSender

WithOptions creates a sender that writes emails into disk And applies the passed options.

func (FileSender) Send

func (ps FileSender) Send(m mail.Message) error

Send sends an email to Sendgrid for delivery, it assumes bodies[0] is HTML body and bodies[1] is text.

type Option

type Option func(*FileSender)

func Only

func Only(contentTypes ...string) Option

Only opens specified content types, without this mailopen opens all of the bodies in the message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL