Sign inSign up

braveokafor/go-mail-api

By braveokafor

•Updated almost 2 years ago

Go Mail API is a simple REST API for sending email notifications via SMTP.

Image
Integration & delivery
Developer tools
Monitoring & observability
0

848

braveokafor/go-mail-api repository overview

⁠Go Mail API

Build Status Release Status Repo size Image size Docker Pulls

⁠Overview

Go Mail API is a simple REST API for sending email notifications via SMTP.

⁠Features

  • Send emails using SMTP.
  • Configurable SMTP settings.
  • Support for environment variables and command-line flags for configuration.

⁠Installation

Download the appropriate binary for your operating system from the GitHub Releases page⁠.

⁠Configuration

The Go Mail API can be configured using environment variables or command-line flags. The following options are available:

Environment VariableCommand-Line FlagDescriptionDefault Value
MAIL_API_PORT--api-portPort for the API server8080
MAIL_SMTP_PORT--smtp-portPort for the SMTP server25
MAIL_SMTP_HOST--smtp-hostHost for the SMTP server(required)
MAIL_SMTP_USER--smtp-userUser for the SMTP server(required)
MAIL_SMTP_PASS--smtp-passPassword for the SMTP server(required)
MAIL_SMTP_USE_TLS--smtp-use-tlsUse TLS for the SMTP serverfalse

Make sure to set the required configuration values (MAIL_SMTP_HOST, MAIL_SMTP_USER, MAIL_SMTP_PASS) either through environment variables or command-line flags.

⁠API Documentation

⁠Send Email

Send an email using the Go Mail API.

  • URL: /send
  • Method: POST
⁠Request Body
FieldTypeRequiredDescription
fromstringYesThe email address of the sender.
toarray of stringsYesThe email addresses of the recipients.
ccarray of stringsNoThe email addresses of the CC recipients.
bccarray of stringsNoThe email addresses of the BCC recipients.
subjectstringYesThe subject of the email.
prioritystringNoThe priority of the email (e.g., "high", "normal", "low").
headersobjectNoAdditional headers to include in the email.
textstringNoThe plain text version of the email body.
htmlstringNoThe HTML version of the email body.
attachmentsarray of attachment objectsNoAttachments to include in the email.
⁠Attachment Object
FieldTypeRequiredDescription
filenamestringYesThe name of the attachment file.
content_typestringYesThe content type of the attachment.
contentstringYesThe content of the attachment, either base64-encoded or plain text.
encodedbooleanNoIndicates whether the content is base64-encoded. Defaults to false.
⁠Response
Status CodeBody
200 OK{"message": "Email sent successfully"}
⁠Example
  1. Set the required configuration values:

    export MAIL_SMTP_HOST="smtp.gmail.com"
    export MAIL_SMTP_USER="[email protected]"
    export MAIL_SMTP_PASS="your app password"
    
  2. Start the Go Mail API server:

    ./go-mail-api --api-port=8080 --smtp-port=587 --smtp-use-tls=true
    
  3. Send a POST request to the /send endpoint:

    curl -X POST -H "Content-Type: application/json" -d '{
      "from": "[email protected]",
      "to": ["[email protected]", "[email protected]"],
      "subject": "Test Email",
      "priority": "high",
      "html": "<p>This is a <strong>test</strong> email.</p>",
      "attachments": [
        {
          "filename": "example.txt",
          "content_type": "text/plain",
          "content": "VGhpcyBpcyBhbiBleGFtcGxlIGF0dGFjaG1lbnQu",
          "encoded": true
        }
      ]
    }' http://localhost:8080/send
    

⁠Contributing

Contributions and suggestions are welcome.
Please open an issue for discussion or propose improvements directly through a pull request.

⁠Support & Issues

Issues Issues

For support or reporting issues, please open an issue in the GitHub repository or reach out on LinkedIn⁠.

Tag summary

Content type

Image

Digest

sha256:04ebd2f0f…

Size

2.2 MB

Last updated

almost 2 years ago

docker pull braveokafor/go-mail-api