marcel

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: MIT Imports: 8 Imported by: 2

README

Marcel

PkgGoDev

Marcel is a tool to generate IETF compliant emails in raw MIME format. I mainly use this for generating emails with attachments and sending them via amazon SES. If that's what you're doing too, you may want notifications

Marcel supports:

  • HTML bodies
  • Text bodies
  • Emails with only an HTML or Text body
  • Attachments
  • JSON serialisation of emails and attachments

Marcel does not support:

  • Inline attachments

Marcel endeavours to pass the IETF Msglint tool with no errors (aside from ReturnPath). If you have a payload that generates errors please file an issue.

Example

package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/davidbanham/marcel"
)

func main() {
	mail := marcel.Email{
		To:      "to@example.com",
		From:    "from@example.com",
		ReplyTo: "reply_to@example.com", // optional
		Text:    "This is the important information in text format",
		HTML:    "This is the important information in <b>HTML</b> format",
		Subject: "A really important email",
		Attachments: []marcel.Attachment{
			marcel.Attachment{
				ContentType: "text/plain",
				Data:        strings.NewReader("A very important attachment"), // Data will be base64 encoded before sending
				Filename:    "test_data.txt",
			},
		},
	}

	rawEmail, err := mail.ToMIME()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(rawEmail))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	ContentType string
	Data        io.Reader
	Filename    string
}

func (*Attachment) MarshalJSON

func (attachment *Attachment) MarshalJSON() ([]byte, error)

func (*Attachment) UnmarshalJSON

func (attachment *Attachment) UnmarshalJSON(data []byte) error

type Email

type Email struct {
	To          string
	From        string
	ReplyTo     string
	Text        string
	HTML        string
	Subject     string
	Attachments []Attachment
}

func (Email) ToMIME

func (email Email) ToMIME() ([]byte, error)

func (Email) WriteMime

func (email Email) WriteMime(dest io.Writer) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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