Created
February 6, 2022 10:55
-
-
Save muhammadqazi/fe1f14ba686b06c4bf8c05dcd66ae664 to your computer and use it in GitHub Desktop.
Go-Authentication
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
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