Skip to content

Instantly share code, notes, and snippets.

@bradrydzewski
Created October 12, 2014 00:10
Show Gist options
  • Save bradrydzewski/c304e05d4e0e493e8f42 to your computer and use it in GitHub Desktop.
Save bradrydzewski/c304e05d4e0e493e8f42 to your computer and use it in GitHub Desktop.
Test Email Configuration
package main
import (
"net/smtp"
)
type Email struct {
Recipients []string
Host string
Port string
From string
Username string
Password string
}
func main() {
e := Email{
Recipients: []string{"[email protected]"},
Host: "smtp.foo.com",
Port: "587",
From: "[email protected]",
Username: "foo",
Password: "bar",
}
auth := smtp.PlainAuth("", e.Username, e.Password, e.Host)
err := smtp.SendMail(e.Host+":"+e.Port, auth, e.From, e.Recipients, []byte(data))
if err != nil {
println(err.Error())
} else {
println("Successfully sent email")
}
}
var data = `
From: %s
To: %s
Subject: TEST EMAIL
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="e255104e821101849e9aefa6986"
--e255104e821101849e9aefa6986
Content-Type: text/plain; charset=UTF-8
THIS IS A TEST
--e255104e821101849e9aefa6986
Content-Type: text/html; charset=UTF-8
<b>THIS IS A TEST</b>
--e255104e821101849e9aefa6986--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment