en Home Sometimes I fall in love with code jgdb A Gopher named Gophy Encode/Decode Golang data to Gob files GoWatch Cfg File Access and Create Time Go Snippets Ping Citadel vCard Sync Your Everyday Go Tools Cases Conv Go jkl Encode/Decode between struct and byte slice Crypt HDKeys Wordlist HDKeys Recover

Smtp

Simplifies the interface to the go smtp package, and creates a pipe for mail queuing

Now gotamer/mail also implements the io.Writer interface. Example:

    package main

    import (
        "fmt"
        
        "bitbucket.org/gotamer/mail"
    )

    func main() {
        s := new(mail.Smtp)
        s.SetHostname("smtp.gmail.com")
        s.SetHostport(587)
        s.SetFromName("GoTamer")
        s.SetFromAddr("xxxx@gmail.com")
        s.SetPassword("*********")
        s.AddToAddr("to@example.com")
        s.SetSubject("GoTamer test smtp mail")
        s.SetBody("The Writer below should replace this default line")
        if _, err := fmt.Fprintf(s, "Hello, smtp mail writer\n"); err != nil {
            fmt.Println(err)
        }
    }

As an alternative to AddToAddr() there is SetToAddrs(). With SetToAddrs() you can set one or more recipients as a comma separated list.

A note on the host.

Go SMTP does not allow to connect to SMPT servers with a self signed certs.

You will get an error like following:

x509: certificate signed by unknown authority

The way I got around that is by using CAcert. CAcert provides FREE digital certificates.

Links

Tags: gotamer


First Created: 2015-01-28T19:54:59Z
Last Modified: 2026-04-05 19:35