tlsmail

package module
v0.0.0-...-68d4d61 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2017 License: MIT Imports: 7 Imported by: 0

README

tlsmail - Sending mail using SSL/TLS with Go

Solution is fully compatible with UTF-8

Install the package using go get github.com/bykovme/tlsmail

Package usage is as simple as shown below, send mails just with one line of code :)

package main

import (
	"log"

	"github.com/bykovme/tlsmail"
)

const subject = "utf-8 mail: mail subject, тема сообщения, メール件名, 邮件主题"

const body = `
hi, привет, こんにちは, 嗨,

utf-8 body: message, сообщение, メッセージ, 信息

Message sent using GO package github.com/bykovme/tlsmail

Enjoy!
`

func main() {

	mail := tlsmail.TLSMail{
		Host:     "mail.your_favorite_hosting_provider.here",           // smtp & auth host
		Port:     "465",                                                // Default port
		Sender:   "noreply@mail_from.here",                             // sender mail id
		Password: "123456",                                             // sender mail password
		TO:       []string{"mail1@mail_to.here", "mail2@mail_to.here"}, // recipients in TO, can be a list
		CC:       []string{"mail3@mail_cc.here", "mail4@mail_cc.here"}, // recipients in CC, can be a list
		Subject:  subject,                                              // Subject in UTF-8
		Body:     body,                                                 // Mail in UTF-8
	}

	err := mail.Send()

	if err != nil {
		log.Println("Mail send failure: " + err.Error())
	} else {
		log.Println("Mail sent successfully")
	}
}

This example can be found here: github.com/bykovme/tlsmail/example.go

Feel free to create issues or send me pull requests.

Find more cool stuff in my blog

Enjoy!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TLSMail

type TLSMail struct {
	Host     string
	Port     string
	Sender   string
	Password string
	TO       []string
	CC       []string
	Subject  string
	Body     string
}

TLSMail - mail structure

func (*TLSMail) BuildMessage

func (tlsmail *TLSMail) BuildMessage() string

BuildMessage - build mail message

func (*TLSMail) CheckMandatoryFields

func (tlsmail *TLSMail) CheckMandatoryFields() error

CheckMandatoryFields - check if all mandatory fields are set

func (*TLSMail) EncodedSubject

func (tlsmail *TLSMail) EncodedSubject() string

EncodedSubject - encode subject according to RFC2047, so UTF can be used

func (*TLSMail) Send

func (tlsmail *TLSMail) Send() error

Send - send mail

func (*TLSMail) ServerName

func (tlsmail *TLSMail) ServerName() string

ServerName - build server name

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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