Use different gmail alias as the e-mail sender address

Viewed 74

I have a function that sends an email.

I'm using go-simple-mail

    server := mail.NewSMTPClient()
    server.Host = "smtp.gmail.com"
    server.Port = 587
    server.Username = "sample@gmail.com"
    server.Password = "password"
    server.Encryption = mail.EncryptionTLS

    smtpClient, err := server.Connect()
    if err != nil {
        log.Fatal(err)
    }

    email := mail.NewMSG()
    email.SetFrom("From me <alias@gmail.com>")
    email.AddTo(receiverEmail)
    email.SetSubject("Forgot Password")

    email.SetBody(mail.TextHTML, htmlBody)

    err = email.Send(smtpClient)

I want to use an alias email, but when I sent the email it still uses sample@gmail.com to the receiver, is there a way to use different email alias?

0 Answers
Related