gomail

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 9 Imported by: 1

README

gomail

This is a Go package for sending emails. It provides functionality to send emails using the SMTP protocol.

Installation

To use the package, you need to have Go installed and Go modules enabled in your project. Then you can add the package to your project by running the following command:

go get -u github.com/mstgnz/gomail

Usage

package main

import (
    "github.com/mstgnz/gomail"
)

func main() {
    // Create a Mail struct and set the necessary fields
    mail := &Mail{
        from:    "sender@example.com",
        name:    "Sender Name",
        host:    "smtp.example.com",
        port:    "587",
        user:    "username",
        pass:    "password",
    }

    // Send the email with text
    err := mail.SetSubject("Test Email").
        SetContent("This is a test email.").
        SetTo([]string{"recipient@example.com"}).
        SendText()
    if err != nil {
        // Handle error
    }

    // Send the email with HTML
    err = mail.SetSubject("Test Email").
        SetContent("<html><body><h1>This is a test email.</h1></body></html>").
        SetTo("recipient@example.com").
        SendHTML()
    if err != nil {
        // Handle error
    }

    // Send the email with attachment
    attachments := map[string][]byte{
        "file.txt": []byte("Attachment content"),
    }
    err = mail.SetSubject("Test Email with Attachment").
        SetContent("This is a test email with attachment.").
        SetTo("recipient@example.com").
        SetAttachment(attachments).
        SendText()
    if err != nil {
        // Handle error
    }
}

Features

  • Uses the SMTP protocol for sending emails.
  • Provides error handling mechanism during email sending process.
  • Allows setting basic parameters required for email sending.

Contributing

Contributions are welcome! For any feedback, bug reports, or contributions, please submit an issue or pull request to the GitHub repository.

License

This package is licensed under the MIT License. See the LICENSE file for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mail

type Mail struct {
	From        string
	Name        string
	Host        string
	Port        string
	User        string
	Pass        string
	Subject     string
	Content     string
	To          []string
	Cc          []string
	Bcc         []string
	Attachments map[string][]byte
	Timeout     time.Duration
	KeepAlive   time.Duration
}

func (*Mail) SendHTML

func (m *Mail) SendHTML() error

SendHTML sends the email with HTML content

func (*Mail) SendText

func (m *Mail) SendText() error

SendText sends the email with plain text content

func (*Mail) SetAttachment

func (m *Mail) SetAttachment(attachments map[string][]byte) *Mail

SetAttachment sets the email attachments

func (*Mail) SetBcc

func (m *Mail) SetBcc(bcc ...string) *Mail

SetBcc sets the email BCC recipients

func (*Mail) SetCc

func (m *Mail) SetCc(cc ...string) *Mail

SetCc sets the email CC recipients

func (*Mail) SetContent

func (m *Mail) SetContent(content string) *Mail

SetContent sets the email content

func (*Mail) SetFrom

func (m *Mail) SetFrom(from string) *Mail

SetFrom sets the sender's email address

func (*Mail) SetHost

func (m *Mail) SetHost(host string) *Mail

SetHost sets the SMTP server host

func (*Mail) SetKeepAlive

func (m *Mail) SetKeepAlive(keepAlive time.Duration) *Mail

SetKeepAlive

func (*Mail) SetName

func (m *Mail) SetName(name string) *Mail

SetName sets the sender's name

func (*Mail) SetPass

func (m *Mail) SetPass(pass string) *Mail

SetPass sets the SMTP server password

func (*Mail) SetPort

func (m *Mail) SetPort(port string) *Mail

SetPort sets the SMTP server port

func (*Mail) SetSubject

func (m *Mail) SetSubject(subject string) *Mail

SetSubject sets the email subject

func (*Mail) SetTimeout

func (m *Mail) SetTimeout(timeout time.Duration) *Mail

SetTimeout

func (*Mail) SetTo

func (m *Mail) SetTo(to ...string) *Mail

SetTo sets the email recipients

func (*Mail) SetUser

func (m *Mail) SetUser(user string) *Mail

SetUser sets the SMTP server username

Jump to

Keyboard shortcuts

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