Skip to content

ShoutboxNET/shoutbox-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Header

Quickstart Docs

Language & Framework guides

Next.js - Typescript - Javascript - Python - PHP - Laravel - Go

Shoutbox Go Client

A Go client library for the Shoutbox email service, supporting both REST API and SMTP implementations.

Setup

For these integrations to work, you will need an account on Shoutbox.net. You can create and copy the required API key on the Shoutbox.net dashboard!

The API key is required for any call to the Shoutbox.net backend; for SMTP, the API key is your password and 'shoutbox' the user to send emails.

Installation

go get github.com/shoutboxnet/shoutbox-go

Environment Setup

Create a .env file based on the template:

make env-template   # Creates .env.template
cp .env.template .env

Then edit .env with your credentials:

SHOUTBOX_API_KEY=your_api_key_here
[email protected]
[email protected]

Available Make Commands

make help          # Show available commands
make build         # Build the main program
make run           # Run the main program (requires env vars)
make test          # Run tests (requires env vars)
make run-rest      # Run REST API example
make run-smtp      # Run SMTP example
make clean         # Clean build artifacts
make env-template  # Create .env.template file

Usage

REST API Client

package main

import (
    "context"
    "log"
    "os"

    "github.com/shoutboxnet/shoutbox-go/shoutbox"
)

func main() {
    client := shoutbox.NewClient(os.Getenv("SHOUTBOX_API_KEY"))

    req := &shoutbox.EmailRequest{
        From:    "[email protected]",
        To:      "[email protected]",
        Subject: "Hello World",
        HTML:    "<h1>Welcome!</h1>",
    }

    err := client.SendEmail(context.Background(), req)
    if err != nil {
        log.Fatal(err)
    }
}

SMTP Client

package main

import (
    "log"
    "os"

    "github.com/shoutboxnet/shoutbox-go/shoutbox"
)

func main() {
    client := shoutbox.NewSMTPClient(os.Getenv("SHOUTBOX_API_KEY"))

    msg := &shoutbox.EmailMessage{
        From:    "[email protected]",
        To:      []string{"[email protected]"},
        Subject: "Hello World",
        HTML:    "<h1>Welcome!</h1>",
    }

    err := client.SendEmail(msg)
    if err != nil {
        log.Fatal(err)
    }
}

Attachments

attachment, err := shoutbox.NewAttachmentFromFile("document.pdf")
if err != nil {
    log.Fatal(err)
}

msg := &shoutbox.EmailMessage{
    From:        "[email protected]",
    To:          []string{"[email protected]"},
    Subject:     "Document Attached",
    HTML:        "<h1>Please find the document attached</h1>",
    Attachments: []shoutbox.Attachment{attachment},
}

Features

  • REST API and SMTP support
  • File attachments
  • Custom headers
  • Reply-to address
  • Sender name
  • Email validation
  • Context support (REST API)
  • Comprehensive testing

Testing

Set up environment variables in .env file and run:

make test

Examples

Check the examples directory for complete usage examples:

  • examples/rest: REST API implementation example
  • examples/smtp: SMTP implementation example with attachments

Run examples using:

make run-rest    # Run REST API example
make run-smtp    # Run SMTP example

Rate Limits

  • 60 requests per minute per API key
  • Maximum attachment size: 10MB
  • Maximum recipients per email: 50

License

MIT License

About

Go client library and docs for the Shoutbox.NET API + SMTP library

Resources

Stars

Watchers

Forks

Packages

No packages published