Skip to content

Instantly share code, notes, and snippets.

@dcaponi
Created August 11, 2021 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcaponi/8c7ce525e91aa3981801d8880c51f62b to your computer and use it in GitHub Desktop.
Save dcaponi/8c7ce525e91aa3981801d8880c51f62b to your computer and use it in GitHub Desktop.
pw_less email sender
package email
import (
"fmt"
"net/smtp"
)
type Emailer interface {
Send(to []string, msg string) error
}
type SimpleEmailer struct {
From, Password, Host, Port string
}
func (e SimpleEmailer) Send(toList []string, body string) error {
auth := smtp.PlainAuth("", e.From, e.Password, e.Host)
from := fmt.Sprintf("From: <%s>\r\n", e.From)
to := fmt.Sprintf("To: <%s>\r\n", toList[0])
subject := "Subject: Basic Functioning Passwordless Email\r\n"
b := fmt.Sprintf("%s\r\n<3 OneLogin", body)
msg := from + to + subject + "\r\n" + b
return smtp.SendMail(e.Host+":"+e.Port, auth, e.From, toList, []byte(msg))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment