exchangesmtp

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: MIT Imports: 11 Imported by: 0

README

exchangesmtp

Simple Go library for sending emails through Microsoft Exchange servers using LOGIN authentication.

Why?

Exchange dropped support for PLAIN auth back in 2017. This library implements LOGIN auth mechanism that still works.

Install

go get github.com/yourusername/exchangesmtp

Usage

Quick send
qs := exchangesmtp.NewQuickSender(
    "user@company.com",           // username
    "password",                    // password
    "smtp.company.com:587",        // server
    "sender@company.com",          // from
    []string{"recipient@company.com"}, // to
)

err := qs.Send("Subject", "Body text")
With attachments
ms := exchangesmtp.NewMailSender("user@company.com", "password", "smtp.company.com:587")

mail := exchangesmtp.Mail{
    MT:      exchangesmtp.HTML,
    From:    "sender@company.com",
    To:      []string{"recipient@company.com"},
    Subject: "Check this out",
    Body:    "<h1>Hello!</h1>",
    Attachment: []exchangesmtp.AttachmentFile{
        {
            Name: "report.pdf",
            Body: fileBytes,
        },
    },
}

err := ms.Send(mail)

Features

  • LOGIN authentication for Exchange
  • Plain text and HTML emails
  • File attachments
  • UTF-8 support
  • Quoted-printable encoding

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoginAuth

func LoginAuth(username, password string) smtp.Auth

LoginAuth uses for authorization in Exchange. Plain auth for Exchange server doesn't work since 2017.

func ValidateEmail added in v1.1.0

func ValidateEmail(email string) bool

ValidateEmail email-address is valid

Types

type AttachmentFile

type AttachmentFile struct {
	Name        string
	ContentType string
	Body        []byte
}

type InlineFile added in v1.1.0

type InlineFile struct {
	CID         string // Content-ID for link in HTML (ex: "logo")
	Name        string
	ContentType string // ex: "image/png"
	Body        []byte
}

type Mail

type Mail struct {
	MT MailType

	From    string
	To      []string
	Subject string
	Body    string

	Attachment []AttachmentFile
	Inline     []InlineFile // для inline-картинок
}

Mail is a struct for two types of email: plain text and html like.

func (*Mail) ToBytes

func (m *Mail) ToBytes() ([]byte, error)

type MailSender

type MailSender struct {
	// contains filtered or unexported fields
}

MailSender uses for send plain text emails.

func NewMailSender

func NewMailSender(username, password, server string) *MailSender

NewMailSender is constructor for MailSender.

func (*MailSender) Send

func (ms *MailSender) Send(mail Mail) error

Send is send simple plain text email to list recipients.

type MailType

type MailType int
const (
	PlainText MailType = iota
	HTML
)

func (MailType) String

func (mt MailType) String() string

type QuickSender

type QuickSender struct {
	// contains filtered or unexported fields
}

func NewQuickSender

func NewQuickSender(user, password, server, from string, to []string) *QuickSender

func (*QuickSender) Send

func (qs *QuickSender) Send(subject, body string) error