emailer

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: GPL-2.0 Imports: 7 Imported by: 0

README

Emailer

Version CI Build GoDoc Report Card License Coverage Status

Purpose

Packaging SMTP(send only) APIs to a choosable option is the goal here, then to have a tiny server that picks 1 provider and serves as HTTP endpoint so the other microservices that belong to you can make email requests.

Supported providers
  • Brevo (highly recommended)
  • Resend
  • Postmark
  • Mailchimp
  • Mailtrap
  • Mailjet
  • Mailgun
  • Sendgrid (avoid them if you can)

Note: Anything that only uses oauth2 like zoho does will not be implemented here for foreseeable future

Getting Started
  export API_KEY=<SECRET_API_KEY>
  export PROVIDER=brevo
  go run ./cmd/emailer/main.go -debug

Kick the server by after having PROVIDER and API_KEY env variables then run go run ./cmd/emailer/main.go

Send Emails

This endpoint allows you to send an email by providing the necessary email details in the request body as JSON.

  • Method: POST
  • URL: /email
  • Request:
    • {
        "from": "sender@example.com",
        "to": ["recipient1@example.com", "recipient2@example.com"],
        "bcc": ["bcc1@example.com", "bcc2@example.com"],
        "cc": ["cc1@example.com", "cc2@example.com"],
        "subject": "Test Email",
        "htmlContent": "<p>This is a test email in HTML format.</p>",
        "textContent": "This is a test email in plain text format."
      }
      
  • Response:
    • 200 Email successfully sent
    • 400 Encoding error or Failed to validate
    • 500 Failed to send email (check logs something went wrong with the provider)
  curl -X POST http://localhost:5555/email \
  -H "Content-Type: application/json" \
  -d '{
    "from": "sender@example.com",
    "to": ["recipient@example.com"],
    "subject": "Test Email",
    "htmlContent": "<p>This is a test email in HTML format.</p>",
    "textContent": "This is a test email in plain text format."
  }'

Documentation

Overview

Package emailer provides shared foundation stones for email providers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandlerFunc added in v0.0.4

func HandlerFunc(sender Sender) http.HandlerFunc

HandlerFunc is opinionated/reusable HTTP handler for brevo provider

Types

type Config added in v0.0.4

type Config struct {
	Key string
	http.Client
}

Config configures the email clients

type Email

type Email struct {
	From        string   `json:"from"`
	To          []string `json:"to"`
	BCC         []string `json:"bcc"`
	CC          []string `json:"cc"`
	Subject     string   `json:"subject"`
	HTMLContent string   `json:"htmlContent"`
	TextContent string   `json:"textContent"`
}

Email is generic email structure for all providers

func (Email) ValidationMsg

func (e Email) ValidationMsg() string

ValidationMsg returns empty if all validations passed, else it will return failed validation message

type Sender

type Sender interface {
	Send(ctx context.Context, e Email) error
}

Sender is a behaviour for email senders

Directories

Path Synopsis
Package brevo makes it easy to send emails via brevo provider.
Package brevo makes it easy to send emails via brevo provider.
cmd
emailer command
Package emailtest makes testing easy for our tests.
Package emailtest makes testing easy for our tests.
Package resend makes it easy to send emails via resend provider.
Package resend makes it easy to send emails via resend provider.

Jump to

Keyboard shortcuts

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