Skip to main content

Install

go get github.com/MelloB1989/karma/mails
go get github.com/MelloB1989/karma/models

Quick start (AWS SES)

package main

import (
  "log"

  "github.com/MelloB1989/karma/mails"
  "github.com/MelloB1989/karma/models"
)

func main() {
  // From address must be verified in AWS SES (or domain verified)
  mailer := mails.NewKarmaMail("[email protected]", mails.AWS_SES)

  // Fill fields as defined in models.SingleEmailRequest
  email := models.SingleEmailRequest{
    // Example fields (check your models package for exact names):
    // To: "[email protected]",
    // Subject: "Welcome to Acme",
    // HTML: "<h1>Hello</h1><p>Thanks for joining.</p>",
    // Text: "Hello\nThanks for joining.",
  }

  if err := mailer.SendSingleMail(email); err != nil {
    log.Fatal(err)
  }
}
Currently, AWS_SES is supported. MAILGUN and SENDGRID return an error: “not supported yet”.

Required environment variables

Set these in your environment (or .env) before running:
AWS_ACCESS_KEY_ID=AKIA...
AWS_SECRET_ACCESS_KEY=xxxxxxxx
AWS_REGION=ap-south-1    # use your AWS region, e.g., us-east-1, eu-west-1, ap-south-1
AWS_SES_REGION=ap-south-1  # This overrides AWS_REGION for SES
Ensure your IAM user/role has SES permissions (e.g. ses:SendEmail, ses:SendRawEmail) in the region you use.

Verify identities in SES

  1. Verify the sender address or verify your domain in SES.
  2. If your account is in the SES sandbox, you must also verify recipient emails (or request production access).
  3. Confirm you’re using the same region for credentials and SES.
Helpful checks:
  • From address (e.g., [email protected]) must be verified.
  • Region in env must match the SES region you configured.

Create a client

mailer := mails.NewKarmaMail("[email protected]", mails.AWS_SES)

Build an email

SendSingleMail expects a models.SingleEmailRequest. Use the exact fields from your models package. Common fields typically include To, Subject, HTML and/or Text.
email := models.SingleEmailRequest{
  // Example – adjust to your struct
  // To:      "[email protected]",
  // Subject: "Your OTP",
  // HTML:    "<p>Your OTP is <b>123456</b></p>",
  // Text:    "Your OTP is 123456",
}

Send and handle errors

if err := mailer.SendSingleMail(email); err != nil {
  // Errors may include:
  // - AWS credentials/region misconfigured
  // - Unverified sender/recipient (SES sandbox)
  // - Provider not supported
  // - Network/SES API errors
  log.Printf("mail send failed: %v", err)
}