func SendEmail(name, email, to, subject, msg,
smtpUser, smtpPass, smtpProvider, smtpPort string) {
var rawMsg = "From: %s <%s>"
rawMsg += "\nTo: %s"
rawMsg += "\nSubject: %s"
rawMsg += "\nMIME-Version: 1.0"
rawMsg += "\nContent-Type: text/html; charset=utf-8"
rawMsg += "\nContent-Transfer-Encoding: plain"
rawMsg += "\n\n%s"
// Set up authentication information.
auth := smtp.PlainAuth("",
smtpUser,
smtpPass,
smtpProvider,
)
// Connect to the server, authenticate, set the sender and recipient,
// and send the email all in one step.
body := fmt.Sprintf(rawMsg, name, email, to, subject, msg)
err := smtp.SendMail(smtpProvider+":"+smtpPort,
auth,
email,
[]string{to},
[]byte(body),
)
if err != nil {
Logs(err)
}
}name := "My Name"
email := "m...@example.com"
to := "m...@golang.com"
subject := "My subject"
smtpUser := "??????@gmail.com"
smtpPass := "**********"
smtpProvider := "smtp.gmail.com"
smtpPort := "587"
SendEmail(name, email, to, subject, msg, smtpUser, smtpPass, smtpProvider, smtpPort)Hello Gophers,I have a problemWhen I try to send email by smtp packageThe sender message is my smtp user, not user who send a messageIs there a way to make the sender from user not smtp user?
Hello Gophers,I have a problemWhen I try to send email by smtp packageThe sender message is my smtp user, not user who send a messageIs there a way to make the sender from user not smtp user?my examplefunc SendEmail(name, email, to, subject, msg,
smtpUser, smtpPass, smtpProvider, smtpPort string) {
var rawMsg = "From: %s <%s>"
rawMsg += "\nTo: %s"
rawMsg += "\nSubject: %s"
rawMsg += "\nMIME-Version: 1.0"
rawMsg += "\nContent-Type: text/html; charset=utf-8"
rawMsg += "\nContent-Transfer-Encoding: plain"
rawMsg += "\n\n%s"