gomailer

package module
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2024 License: MIT Imports: 14 Imported by: 0

README

Gomailer

Gomailer is a simple Go library for sending emails from Go applications. It supports sending text or HTML emails, email templates, email attachments and many more.

Installation 🛠️

To use Gomailer, you need to have Go installed. Once you have Go installed, you can use the following command to install Gomailer:

go get github.com/patrickkabwe/gomailer
Features 🚀
  • Send emails from Go applications
  • Text or HTML email content supported
  • Email templates
  • Email Attachments - (WIP)
  • Secure connections(SSL/TLS) - (WIP)
Usage 📝

Here's an example of how to use Gomailer to send an email:

package main

import (
    "github.com/patrickkabwe/gomailer"
)

func main() {
    options := gomailer.GoMailerOption{
        Host:     "smtp.gmail.com",
        Port:     587,
        Username: "your_username",
        Password: "your_password",
    }

    gm := gomailer.New(options)

    message := gomailer.EmailMessage{
        From:    "your_email_address",
        To:      []string{"recipient_email_address"},
        Subject: "Test email from Gomailer",
        Body:    []byte("This is a test email sent from Gomailer."),
    }

    err := gm.SendMail(message)
    if err != nil {
        // Handle error
    }
}
API
GoMailerOption

Host - host to use when sending the email Port - port to use when sending the email Username - username to use when authenticating to the SMTP server Password - password to use when authenticating to the SMTP server

EmailMessage

From - the email address of the sender of the email To - a slice of email addresses to send the email to Subject - the subject of the email Body - can be a string (text) or (html)

New(options GoMailerOption) GoMailer

Returns a new GoMailer instance with the provided options.

SendMail(message EmailMessage) error

Sends an email using the provided message and options.

License

Gomailer is released under the MIT License. See LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment added in v0.1.1

type Attachment struct {
	// Name is the name of the attachment
	Name string
	// Path is the path to the attachment file
	Path string
}

type EmailMessage

type EmailMessage struct {
	// Name is the name of the sender of the email
	Name string
	// From is the email address of the sender of the email
	From string
	// To is a slice of email addresses to send the email to
	To []string
	// Subject is the subject of the email
	Subject string
	// Body can be a string (text) or (html)
	Body []byte
	// Attachments is a slice of file paths to attach to the email
	Attachments []Attachment
	// CC is a slice of email addresses to send a copy of the email to
	CC []string
	// BCC is a slice of email addresses to send a blind copy of the email to
	BCC []string
	// ReplyTo is the email address to use when replying to the email
	ReplyTo string
	// Template is the path to the template file to use when sending the email
	Template Template
}

type GoMailer

type GoMailer interface {
	// SendMail sends an email using the provided message and options
	SendMail(message EmailMessage) error
}

GoMailer is the interface that wraps the basic SendMail method for sending emails

func New

func New(options GoMailerOption) GoMailer

New returns a new GoMailer instance with the provided options

type GoMailerOption

type GoMailerOption struct {
	// host to use when sending the email
	Host string
	// port to use when sending the email
	Port int
	// username to use when authenticating to the smtp server
	Username string
	// password to use when authenticating to the smtp server
	Password string
	// secure indicates whether to use a secure connection when sending the email (e.g. SSL/TLS)
	Secure bool
}

type Template added in v0.1.1

type Template struct {
	// Path is the path to the template file
	Path string
	// Data is the data to use when rendering the template
	Data interface{}
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL