Original post

I am not a go programmer, but I need to modify some code. In this code:

// sendmail invokes go's sendmail method
func sendmail(payload []byte, sendTo []string) (err error) {

        if cfg.Mail.SMTPAuth {
                auth := smtp.PlainAuth(
                "",
                cfg.Mail.Username,
                cfg.Mail.Password,              
                cfg.Mail.SMTPRelay)     //not thru tor
                } else {
                auth := smtp.PlainAuth(
                "",
                cfg.Mail.Username,
                cfg.Mail.Password,
                "")                                     //thru tor
                }

   relay := fmt.Sprintf("%s:%d", cfg.Mail.SMTPRelay, cfg.Mail.SMTPPort)
   err = smtp.SendMail(relay, auth, cfg.Remailer.Address, sendTo, payload)
   if err != nil {
      Warn.Println(err)
      return
   }
   return
}

I am getting this error:
$ go build
.mail.go:450:31: undefined: auth

Line 450 = smtp.SendMail… line.

The auth := was not wrapped in the if statement before, but I need to change the auth according to the if test. If you can show how to just change the last line in the auth only (cfg.Mail.SMTPRelay) to “” and back), that would work also.
Can some show how to get around this error?

Thanks