rmailer

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: AGPL-3.0 Imports: 15 Imported by: 0

README

rmailer

library in go to send mails with attachments via smtp protocol

package main

import (
  rmailer "github.com/RaoH37/rmailer"
  "net/mail"
)

func main() {
  sender := rmailer.NewSender("[email protected]", "secret", "mta.toto.fr:465")
  
  htmlContent := "<p>It's <u>a good day</u> <i>to do nothing !</i></p>"
  txtContent := "It's a good day to do nothing !"

  m := rmailer.NewMessage("Hello", txtContent, htmlContent)

  m.From = mail.Address{Address: "[email protected]"}
  m.To = []mail.Address{
    {Address: "[email protected]"},
  }

  m.AttachFile("/tmp/file_1.txt")
  m.AttachFile("/tmp/file_2.txt")

  sender.Send(m)
}

Documentation

Index

Constants

View Source
const (
	ContentTypeMultipartMixed          = "multipart/mixed"
	ContentTypeMultipartAlternative    = "multipart/alternative"
	ContentTypeTextHtml                = "text/html"
	ContentTypeTextPlain               = "text/plain"
	ContentTypeLine                    = "Content-Type: %s\n"
	ContentTypeLineBoundary            = "Content-Type: %s; boundary=%s\n\n--%s\n"
	ContentTransfertEncodingBase64Line = "Content-Transfer-Encoding: base64\n"
	MimeVersionLine                    = "MIME-Version: 1.0\n"
	BoundaryLine                       = "\n\n--%s\n"
	ContentDispositionAttachmentLine   = "Content-Disposition: attachment; filename=\"=?UTF-8?B?%s?=\"\r\n\r\n"
	BackLine                           = "\r\n"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	From        mail.Address
	To          []mail.Address
	CC          []mail.Address
	BCC         []mail.Address
	Subject     string
	BodyText    string
	BodyHtml    string
	Attachments map[string][]byte
}

func NewMessage

func NewMessage(subject, text string, html string) *Message

func (*Message) AttachFile

func (m *Message) AttachFile(path string) error

func (*Message) SetBccFromStrings added in v1.1.1

func (m *Message) SetBccFromStrings(ss []string)

func (*Message) SetCcFromStrings added in v1.1.1

func (m *Message) SetCcFromStrings(ss []string)

func (*Message) SetFromFromString added in v1.1.1

func (m *Message) SetFromFromString(s string)

func (*Message) SetToFromStrings added in v1.1.1

func (m *Message) SetToFromStrings(ss []string)

func (*Message) ToBytes

func (m *Message) ToBytes() []byte

type MessageBuilder added in v1.2.0

type MessageBuilder struct {
	Message *Message
	Coder   *base64.Encoding
}

func (*MessageBuilder) BodyHtmlLine added in v1.2.0

func (mb *MessageBuilder) BodyHtmlLine() string

func (*MessageBuilder) BodyLine added in v1.2.0

func (mb *MessageBuilder) BodyLine(content string, contentType string) string

func (*MessageBuilder) BodyTextLine added in v1.2.0

func (mb *MessageBuilder) BodyTextLine() string

func (*MessageBuilder) CcLine added in v1.2.0

func (mb *MessageBuilder) CcLine() string

func (*MessageBuilder) FromLine added in v1.2.0

func (mb *MessageBuilder) FromLine() string

func (*MessageBuilder) SubjectLine added in v1.2.0

func (mb *MessageBuilder) SubjectLine() string

func (*MessageBuilder) ToLine added in v1.2.0

func (mb *MessageBuilder) ToLine() string

type Sender

type Sender struct {
	UserName string
	Password string
	Host     string
}

func NewSender

func NewSender(username string, password string, host string) *Sender

func (*Sender) AnonymousSend

func (s *Sender) AnonymousSend(m *Message) error

func (*Sender) AuthenticatedSend

func (s *Sender) AuthenticatedSend(m *Message) error

func (*Sender) IsAuthenticated

func (s *Sender) IsAuthenticated() bool

func (*Sender) Send

func (s *Sender) Send(m *Message) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳