A Go package that facilitates sending emails with optional attachments using SMTP. It supports TLS for secure connections.
Go to file
Urko. bbf75783e7 feat: add README 2023-10-21 19:05:48 +02:00
testdata refactor: project structure 2023-10-21 19:05:42 +02:00
.gitignore feat: add gitignore 2023-10-21 18:40:53 +02:00
README.md feat: add README 2023-10-21 19:05:48 +02:00
email.go refactor: project structure 2023-10-21 19:05:42 +02:00
email_test.go refactor: project structure 2023-10-21 19:05:42 +02:00
go.mod feat: email service 2023-10-21 18:45:33 +02:00
go.sum feat: email service 2023-10-21 18:45:33 +02:00

README.md

Mail Sender

Description

mail-sender is a simple Go library designed to send emails with optional attachments. It's built on top of the standard Go net/smtp library with additional support for sending HTML emails and handling multiple attachments.

Features

  • Send HTML emails.
  • Attach multiple files to the email.
  • Built-in support for TLS encryption.
  • Simple API for sending emails.

Installation

Clone this repository:

git clone https://gitea.urkob.com/urko/mail-sender.git

Usage

Here's a basic example on how to use the mail-sender:

  1. Initialize the Email Service
config := email.MailServiceConfig{
    Auth: smtp.PlainAuth("", "your@email.com", "your-password", "smtp.youremail.com"),
    Host: "smtp.youremail.com",
    Port: "587",
    From: "your@email.com",
}
mailService := email.NewMailService(config)
  1. Send an Email with an Attachment
emailData := email.EmailMessage{
    To:      "receiver@email.com",
    Subject: "Test Email",
    Body:    "<h1>Hello!</h1><p>This is a test email.</p>",
    Attachments: []email.EmailAttachment{
        {
            File:  attachmentFile, // This is an io.Reader
            Title: "document.pdf",
        },
    },
}
err := mailService.SendEmail(emailData)
if err != nil {
    log.Fatal(err)
}

Dependencies

  • Go's standard net/smtp package
  • Go's standard crypto/tls package for secure email sending.

Contribution

Feel free to submit issues or pull requests if you find any bugs or have suggestions for improvements.