Skip to content

Instantly share code, notes, and snippets.

@muhammadqazi
Created February 6, 2022 10:55
Show Gist options
  • Save muhammadqazi/fe1f14ba686b06c4bf8c05dcd66ae664 to your computer and use it in GitHub Desktop.
Save muhammadqazi/fe1f14ba686b06c4bf8c05dcd66ae664 to your computer and use it in GitHub Desktop.
Go-Authentication
func HandleEmailService(email string, code int) {
godotenv.Load(".env")
sender := os.Getenv("email")
Senderauth := os.Getenv("password")
to := []string{email}
from := sender
password := Senderauth
host := "smtp.gmail.com"
port := "587"
address := host + ":" + port
subject := "Subject: Our Golang Email\n"
body := "Email from GO-Authentication \nVerification code is : " + strconv.Itoa(code)
message := []byte(subject + body)
auth := smtp.PlainAuth("", from, password, host)
err := smtp.SendMail(address, auth, from, to, message)
if err != nil {
fmt.Println("err:", err)
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment