mailx

package module
v0.0.0-...-3b22920 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: MIT Imports: 14 Imported by: 1

README

mailx

Go Report Card GoDoc

A lightweight SMTP mail library

❤️ A project by txthinking.com

Install

$ go get github.com/txthinking/mailx

Example

server := &mailx.SMTP{
    Server:   "smtp.mailtrap.io",
    Port:     465,
    UserName: "e3f534cfe656f4",
    Password: "b6e38ddc0f1e9d",
}

message := &mailx.Message{
    From: &mail.Address{
        Name:    "mailx",
        Address: "739f35c64d-48cf45@inbox.mailtrap.io",
    },
    To: []*mail.Address{
        {
            Name:    "Cloud",
            Address: "cloud@txthinking.com",
        },
    },
    Subject: "Hello",
    Body:    "I <b>love</b> U.",
    Attachment: []string{
        "/etc/hosts",
    },
}

if err := server.Send(message); err != nil {
    log.Fatal(err)
}

License

Licensed under The MIT License

Documentation

Overview

Package mailx is a lightweight SMTP/Mailgun/etc mail sender. Implement RFC0821, RFC0822, RFC1869, RFC2045, RFC2821 Support html body, don't worry that the receiver's mail client can't support html, because Mailer will send both text/plain and text/html body, so if the mail client can't support html, it will display the text/plain body.

Example
package main

import (
	"log"
	"net/mail"

	"github.com/txthinking/mailx"
)

func main() {
	server := &mailx.SMTP{
		Server:   "smtp.mailtrap.io",
		Port:     465,
		UserName: "e3f534cfe656f4",
		Password: "b6e38ddc0f1e9d",
	}

	message := &mailx.Message{
		From: &mail.Address{
			Name:    "mailx",
			Address: "739f35c64d-48cf45@inbox.mailtrap.io",
		},
		To: []*mail.Address{
			{
				Name:    "Cloud",
				Address: "cloud@txthinking.com",
			},
		},
		Subject: "Hello",
		Body:    "I <b>love</b> U.",
		Attachment: []string{
			"/etc/hosts",
		},
	}

	if err := server.Send(message); err != nil {
		log.Fatal(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChunkSplit

func ChunkSplit(s string) (string, error)

Chunk data using RFC 2045.

func MakeBoundary

func MakeBoundary() string

Create boundary for MIME data.

Types

type Message

type Message struct {
	From       *mail.Address
	FakeFrom   *mail.Address
	To         []*mail.Address
	Subject    string
	Body       string
	Attachment []string
	// contains filtered or unexported fields
}

Message is the email body.

func (*Message) Reader

func (m *Message) Reader() (io.Reader, error)

Reader return a io.Reader of mail message.

type SMTP

type SMTP struct {
	Server   string
	Port     int
	UserName string
	Password string
}

SMTP is your SMTP server config.

func (*SMTP) Send

func (m *SMTP) Send(msg *Message) error

Send mail by smtp. RFC 821,822,1869,2821.

Jump to

Keyboard shortcuts

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