{"id":37204544,"url":"https://github.com/malcolm-davis/go-sendmail","last_synced_at":"2026-01-14T23:34:53.173Z","repository":{"id":312086609,"uuid":"1046000596","full_name":"malcolm-davis/go-sendmail","owner":"malcolm-davis","description":"go-sendmail general interface and message builder for SendGrid, MailerSend, MailJet, smtp2go, and mailtrap","archived":false,"fork":false,"pushed_at":"2025-08-28T14:41:44.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-08T12:28:57.694Z","etag":null,"topics":["go","golang","mail","mailersend","mailjet","mailtrap","sendgrid","smpt2go"],"latest_commit_sha":null,"homepage":"https://malcolm-davis.github.io/go-sendmail/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/malcolm-davis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-28T03:29:29.000Z","updated_at":"2025-08-28T15:12:17.000Z","dependencies_parsed_at":"2025-08-28T19:45:16.607Z","dependency_job_id":"261651c8-f716-416e-99de-ba8937751875","html_url":"https://github.com/malcolm-davis/go-sendmail","commit_stats":null,"previous_names":["malcolm-davis/go-sendmail"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/malcolm-davis/go-sendmail","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malcolm-davis%2Fgo-sendmail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malcolm-davis%2Fgo-sendmail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malcolm-davis%2Fgo-sendmail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malcolm-davis%2Fgo-sendmail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/malcolm-davis","download_url":"https://codeload.github.com/malcolm-davis/go-sendmail/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malcolm-davis%2Fgo-sendmail/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28438820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","mail","mailersend","mailjet","mailtrap","sendgrid","smpt2go"],"created_at":"2026-01-14T23:34:52.701Z","updated_at":"2026-01-14T23:34:53.164Z","avatar_url":"https://github.com/malcolm-davis.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-sendmail\n\n## Summary\n\ngo-sendmail is a wrapper to mail service libraries.\n\n## Overview\n\nEach mail service requires registration, which includes configuring the domain's DNS for the specific service using a combination of CNAME \u0026 TXT additions.\n\nSome of the services also require a knowledge of who is allowed to send emails from the domain, which helps restrict access.\n\nRestricting the use of a domain in the 'from' email clause makes sense because libraries are generally intended to be part of an automated process, rather than originating from multiple users within a domain.\n\n### Features\n\n- **sendmail interface**: Common interface to all mailclients\n- **Cache**: Reuses the client instance across the application\n- **MessageBuilder**: Provide a builder pattern to build messasges\n- **stopwatch**: Auto stopwatch each message posted\n- **Log override**: Provides logging override.  The default logging is slog\n\n### Wrappers provided for\n\n- SendGrid's Go Library at https://github.com/sendgrid/sendgrid-go\n- MailerSend Go Lib at  https://github.com/mailersend/mailersend-go\n- MailJet Go Lib at https://github.com/mailjet/mailjet-apiv3-go\n- smtp2go Go Lib at https://github.com/smtp2go-oss/smtp2go-go\n- mailtrap - wrapper around mailtrap json api request\n\n\n### Install\n\n```\ngo get github.com/malcolm-davis/go-sendmail\n```\n\n### Usage\n\n#### Basic\n\n```go\npackage main\n\nimport (\n    \"log/slog\"\n    \"os\"\n    \"time\"\n\n    \"github.com/malcolm-davis/go-sendmail\"\n)\n\nfunc main() {\n    // Create a new stopwatch and start it\n    send, err := sendmail.NewSendGrid(os.Getenv(\"SENDGRID_API_KEY\"))\n    if(err!=nil) {\n        slog.Error(\"Error connecting to sendgrid service\", err)\n    }\n\n    respnse, err := send.SendMail(\"From User\", \"test@example.com\" \"To User\", \"to@example.com\")  \"Sending with Twilio SendGrid is Fun\",\n         \"and easy to do anywhere, even with Go\", \"\u003cstrong\u003eand easy to do anywhere, even with Go\u003c/strong\u003e\") \n    if(err!=nil) {\n        slog.Error(\"Error sending message\", err)\n    }\n}\n```\n\n#### Message Builder\n\n```go\npackage main\n\nimport (\n    \"log/slog\"\n    \"os\"\n    \"time\"\n\n    \"github.com/malcolm-davis/go-sendmail\"\n)\n\nfunc main() {\n    fmt.Println(\"Starting mailjet example\")\n    fmt.Println(\"Make sure to set MAILJET_APIKEY and MAILJET_SECRETKEY environment variables\")\n    send, err := sendmail.NewMailJetMailManager(os.Getenv(\"MAILJET_API_KEY\"), os.Getenv(\"MAILJET_SECRET_KEY\"))\n    if err != nil {\n        slog.Error(\"Error connecting to mailjet service\", \"error\", err)\n        return\n    }\n\n    messageBuilder := sendmail.NewEmailMessage()\n\n    // Note: the from email address requires authentication in MailJet\n    messageBuilder.FromEmail(\"do-not-reply\", \"do-not-reply@example.dev\")\n    messageBuilder.AddRecipient(\"name\", \"user@example.com\")\n    messageBuilder.AddRecipient(\"name 2\", \"user2@example.com\")\n    messageBuilder.Subject(\"contact us email\")\n    messageBuilder.PlainTextContent(\"Test mailjet\")\n    messageBuilder.HtmlContent(\"\u003cstrong\u003eand easy to do anywhere, even with Go\u003c/strong\u003e\")\n\n    message, err := messageBuilder.Build()\n    if err != nil {\n        slog.Error(\"Error building message\", \"error\", err)\n        return\n    }\n    response, err := send.SendMessage(message)\n    if err != nil {\n        slog.Error(\"Error sending message\", \"error\", err)\n        return\n    }\n\n    // if the response is successful, print the status code 200\n    // however, if the from email address is not a verified domain in mailjet, a 200 will be returned, but no mail delivery will occur\n    fmt.Println(\"response.StatusCode\", response.StatusCode)\n}\n```\n\n\n#### smtp2go\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"log/slog\"\n    \"os\"\n\n    \"github.com/malcolm-davis/go-sendmail\"\n)\n\nfunc main() {\n    fmt.Println(\"Starting smtp2go example\")\n    fmt.Println(\"Make sure to set SMTP2GO_API_KEY\")\n    send, err := sendmail.NewSmtp2go()\n    if err != nil {\n        slog.Error(\"Error connecting to smtp2go service\", \"error\", err)\n        return\n    }\n\n    messageBuilder := sendmail.NewEmailMessage()\n\n    // Note: the from email address requires authentication in Smtp2go\n    messageBuilder.FromEmail(\"do-not-reply\", \"do-not-reply@example.com\")\n    messageBuilder.AddRecipient(\"user\", \"user@example.com\")\n    messageBuilder.Subject(\"contact us email\")\n    messageBuilder.PlainTextContent(\"Test smtp2go\")\n    messageBuilder.HtmlContent(\"\u003cstrong\u003eand easy to do anywhere, even with Go\u003c/strong\u003e\")\n\n    message, err := messageBuilder.Build()\n    if err != nil {\n        slog.Error(\"Error building message\", \"error\", err)\n        return\n    }\n    response, err := send.SendMessage(message)\n    if err != nil {\n        slog.Error(\"Error sending message\", \"error\", err)\n        return\n    }\n\n    // if the response is successful, print the status code 200\n    // however, if the from email address is not a verified domain in mailjet, a 200 will be returned, but no mail delivery will occur\n    fmt.Println(\"response.StatusCode\", response.StatusCode)\n\n}\n```\n\n#### Message Builder\n\n```go\npackage main\n\nimport (\n    \"log/slog\"\n    \"os\"\n    \"time\"\n\n    \"github.com/malcolm-davis/go-sendmail\"\n)\n\nfunc main() {\n    fmt.Println(\"Starting mailjet example\")\n    fmt.Println(\"Make sure to set MAILJET_APIKEY and MAILJET_SECRETKEY environment variables\")\n    send, err := sendmail.NewMailJet(os.Getenv(\"MAILJET_API_KEY\"), os.Getenv(\"MAILJET_SECRET_KEY\"))\n    if err != nil {\n        slog.Error(\"Error connecting to mailjet service\", \"error\", err)\n        return\n    }\n\n    messageBuilder := sendmail.NewEmailMessage()\n\n    // Note: the from email address requires authentication in MailJet\n    messageBuilder.FromEmail(\"do-not-reply\", \"do-not-reply@example.dev\")\n    messageBuilder.AddRecipient(\"name\", \"user@example.com\")\n    messageBuilder.AddRecipient(\"name 2\", \"user2@example.com\")\n    messageBuilder.Subject(\"contact us email\")\n    messageBuilder.PlainTextContent(\"Test mailjet\")\n    messageBuilder.HtmlContent(\"\u003cstrong\u003eand easy to do anywhere, even with Go\u003c/strong\u003e\")\n\n    message, err := messageBuilder.Build()\n    if err != nil {\n        slog.Error(\"Error building message\", \"error\", err)\n        return\n    }\n    response, err := send.SendMessage(message)\n    if err != nil {\n        slog.Error(\"Error sending message\", \"error\", err)\n        return\n    }\n\n    // if the response is successful, print the status code 200\n    // however, if the from email address is not a verified domain in mailjet, a 200 will be returned, but no mail delivery will occur\n    fmt.Println(\"response.StatusCode\", response.StatusCode)\n}\n```\n\n\n#### MailTrap with image and multiple recipients\n\n```go\nimport (\n    \"fmt\"\n    \"log/slog\"\n    \"os\"\n\n    \"github.com/malcolm-davis/go-sendmail\"\n)\n\nfunc main() {\n    fmt.Println(\"Make sure you have set the MAILTRAP_API_KEY in an environment variable\")\n\n    // Create a new sendmail manager and init\n    send, err := sendmail.NewMailTrap(os.Getenv(\"MAILTRAP_API_KEY\"))\n    if err != nil {\n        slog.Error(\"Error connecting to sendgrid service\", \"error\", err)\n        return\n    }\n\n    // Message builder example\n    messageBuilder := sendmail.NewEmailMessage()\n    messageBuilder.FromEmail(\"do-not-reply\", \"do-not-reply@example.dev\")\n    messageBuilder.AddRecipient(\"Use \", \"user_1@example.com\")\n    messageBuilder.AddRecipient(\"User 2\", \"user_2@example.com\")\n    messageBuilder.Subject(\"Transactional email from mailtrap\")\n    messageBuilder.PlainTextContent(\"Test go-sendemail mailtrap feature\")\n    messageBuilder.AddAttachment(\"image/png\", \"test.png\",\n        \"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAD1JREFUOI1jYKAQMJKhJxKJvZyJUhewEKEG2ZJ/5BjwF4mN4WWKvUCTMPiPxCYYS4PDCyQ5meouGAYGUAwAmxIFIoTEH0QAAAAASUVORK5CYII=\")\n\n    message, err := messageBuilder.Build()\n    if err != nil {\n        slog.Error(\"Error building message\", \"error\", err)\n        return\n    }\n\n    response, err := send.SendMessage(message)\n    if err != nil {\n        slog.Error(\"Error sending message\", \"error\", err)\n        return\n    }\n    fmt.Println(\"response.StatusCode\", response.StatusCode)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalcolm-davis%2Fgo-sendmail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalcolm-davis%2Fgo-sendmail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalcolm-davis%2Fgo-sendmail/lists"}