Created
August 11, 2021 19:19
-
-
Save dcaponi/8c7ce525e91aa3981801d8880c51f62b to your computer and use it in GitHub Desktop.
pw_less email sender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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