goemail

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2025 License: MIT Imports: 10 Imported by: 0

README

📧 GoEmail – Simple and Fast Email Sending in Go

GoeEmail is a lightweight and easy-to-use package for sending emails using Go (Golang). It supports SMTP authentication, HTML/plain text messages, attachments, and more – all with a clean and developer-friendly API.


✨ Features

  • 📤 Send plain text or HTML emails
  • ✅ Supports SMTP authentication (username/password)
  • 💡 Easy integration with your Go applications

🚀 Getting Started

Installation
go get github.com/Priyokumar/goemail
Example:
m, err := goemail.New(
		goemail.ConnectionDetails{
			SmtpHost:     "xxxxxx",
			SmtpPort:     000,
			SmtpUser:     "xxxx",
			SmtpPassword: "xxx",
		})

	if err != nil {
		log.Println(err)
		return
	}
	m.SetTo([]string{"xxxxxx"})
	m.SetSubject("Test")
	m.SetSenderName("test")
	m.SetSender("xxxxxx")
	m.SetReturnEmail("xxxxxx")
	m.SetContent(
		goemail.Content{
			Type:    goemail.ContentHTML,
			Content: "<div><h2>Test</h2></div>",
		},
	)

	ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Second*50))
	defer cancel()
	err = m.Send(ctx, 10)

	if err != nil {
		log.Println(err)
		return
	}

For sending text emails, you can use the ContentText type:

m.SetContent(
		goemail.Content{
			Type:    goemail.ContentText,
			Content: "This is a test email",
		},
	)

For attaching files to emails:

m.SetAttachments([]string{"path/to/your/file.txt"})

Documentation

Index

Constants

View Source
const (
	ContentHTML = "html"
	ContentText = "text"
)

ContentHTML represents the content type for HTML emails.

Variables

This section is empty.

Functions

func New

func New(c ConnectionDetails) (*email, error)

New creates a new email instance using the provided connection details. It validates the connection details and initializes a dialer for sending emails.

Parameters:

  • c: ConnectionDetails containing SMTP host, port, user, and password.

Returns:

  • *email: A pointer to the initialized email instance.
  • error: An error if the connection details validation fails or any other issue occurs.

Types

type ConnectionDetails

type ConnectionDetails struct {
	SmtpHost     string
	SmtpPort     int
	SmtpUser     string
	SmtpPassword string
}

ConnectionDetails holds the configuration details required to establish a connection to an SMTP server for sending emails. It includes the server host, port, and authentication credentials.

type Content

type Content struct {
	Type         string
	Content      string
	TemplatePath string
	Data         interface{}
}

Content represents the structure for email content. It includes the type of content, the actual content, an optional template path for rendering, and any associated data.

Fields: - Type: Specifies the type of the content (e.g., "text/plain", "text/html"). - Content: The actual content of the email as a string. - TemplatePath: Path to the template file used for rendering the content (optional). - Data: Data to be used for populating the template (if applicable).

type MailDetails

type MailDetails struct {
	To      []string
	Cc      []string
	Bcc     []string
	Subject string

	Sender      string
	SenderName  string
	ReturnEmail string
	Tags        string

	Content       Content
	ImagesToEmbed []string
}

MailDetails represents the details of an email to be sent. It includes information about the recipients, sender, subject, and content.

Fields: - To: A list of recipient email addresses. - Cc: A list of email addresses to be included in the CC (carbon copy) field. - Bcc: A list of email addresses to be included in the BCC (blind carbon copy) field. - Subject: The subject line of the email. - Sender: The email address of the sender. - SenderName: The name of the sender to be displayed in the email. - ReturnEmail: The email address to which replies should be sent. - Tags: Tags associated with the email for categorization or tracking purposes. - Content: The main content of the email, represented by a Content struct. - ImagesToEmbed: A list of file paths for images to be embedded in the email.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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