gogomail

How to set reply-to email address using gomail


I am trying to send email using gomail, need to set reply-to email address. Searched a lot but did not get any relevant link.

package main

import "gopkg.in/gomail.v2"

func main() {
   m := gomail.NewMessage()
   m.SetAddressHeader("From", "sender@example.com", "Sandy Sender")
   m.SetAddressHeader("To", "recipient@example.com")
   m.SetHeader("Subject", "Hello!")
   m.SetBody("text/plain", "This is the body of the message.")

   d := gomail.NewPlainDialer("smtp.example.com", 587, "user", "123456")

   if err := d.DialAndSend(m); err != nil {
    panic(err)
    }
}

Solution

  • You can set the Reply-To header for that effect:

    m.SetAddressHeader("Reply-To", "noreply@example.com")