Go Mail API is a simple REST API for sending email notifications via SMTP.
- Send emails using SMTP.
- Configurable SMTP settings.
- Support for environment variables and command-line flags for configuration.
Download the appropriate binary for your operating system from the GitHub Releases page.
The Go Mail API can be configured using environment variables or command-line flags. The following options are available:
Environment Variable | Command-Line Flag | Description | Default Value |
---|---|---|---|
MAIL_API_PORT |
--api-port |
Port for the API server | 8080 |
MAIL_SMTP_PORT |
--smtp-port |
Port for the SMTP server | 25 |
MAIL_SMTP_HOST |
--smtp-host |
Host for the SMTP server | (required) |
MAIL_SMTP_USER |
--smtp-user |
User for the SMTP server | (required) |
MAIL_SMTP_PASS |
--smtp-pass |
Password for the SMTP server | (required) |
MAIL_SMTP_USE_TLS |
--smtp-use-tls |
Use TLS for the SMTP server | false |
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.
Send an email using the Go Mail API.
- URL:
/send
- Method:
POST
Field | Type | Required | Description |
---|---|---|---|
from |
string | Yes | The email address of the sender. |
to |
array of strings | Yes | The email addresses of the recipients. |
cc |
array of strings | No | The email addresses of the CC recipients. |
bcc |
array of strings | No | The email addresses of the BCC recipients. |
subject |
string | Yes | The subject of the email. |
priority |
string | No | The priority of the email (e.g., "high", "normal", "low"). |
headers |
object | No | Additional headers to include in the email. |
text |
string | No | The plain text version of the email body. |
html |
string | No | The HTML version of the email body. |
attachments |
array of attachment objects | No | Attachments to include in the email. |
Field | Type | Required | Description |
---|---|---|---|
filename |
string | Yes | The name of the attachment file. |
content_type |
string | Yes | The content type of the attachment. |
content |
string | Yes | The content of the attachment, either base64-encoded or plain text. |
encoded |
boolean | No | Indicates whether the content is base64-encoded. Defaults to false . |
Status Code | Body |
---|---|
200 OK |
{"message": "Email sent successfully"} |
-
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"
-
Start the Go Mail API server:
./go-mail-api --api-port=8080 --smtp-port=587 --smtp-use-tls=true
-
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
Contributions and suggestions are welcome.
Please open an issue for discussion or propose improvements directly through a pull request.
For support or reporting issues, please open an issue in the GitHub repository or reach out on LinkedIn.