I am trying to send a simple email using GO using the built-in functionality of the smtp package.
My simple code looks like this:
func sendEmail(to string, body []byte) error { auth := smtp.PlainAuth( "", config.SmtpUsername, config.SmtpPassword, config.SmtpHostname, ) return smtp.SendMail( fmt.Sprintf("%s:%d", config.SmtpHostname, config.SmtpPort), auth, config.SmtpUsername, []string{to}, body, ) }
And everything works, the fact is that it always sets the Return-Path header to config.SmtpUsername, even if I send a message containing the custom Return-Path header, basically after sending the message, it seems that somehow the return path from The message is replaced with the smtp username.
Any thoughts on how I could avoid this and make GO, use any return path that I give?
LE 1: If any help, a code snippet is available at: http://play.golang.org/p/ATDCgJGKZ3
LE 2: I can achieve the desired behavior from php using swiftmailer, so I donβt think the delivery server is changing the headers in any way.
More code:
PHP with swiftmailer, it sets the correct return path:
Yii::import('common.vendors.SwiftMailer.lib.classes.Swift', true); Yii::registerAutoloader(array('Swift', 'autoload')); Yii::import('common.vendors.SwiftMailer.lib.swift_init', true); $hostname = ''; $username = ''; $password = ''; $returnPath = ''; $subject = 'Swiftmailer sending, test return path'; $toEmail = ''; $transport = Swift_SmtpTransport::newInstance($hostname, 25); $transport->setUsername($username); $transport->setPassword($password); $logger = new Swift_Plugins_LoggerPlugin(new Swift_Plugins_Loggers_ArrayLogger()); $mailer = Swift_Mailer::newInstance($transport); $mailer->registerPlugin($logger); $message = Swift_Message::newInstance(); $message->setReturnPath($returnPath); $message->setSubject($subject); $message->setFrom($username); $message->setTo($toEmail); $message->setBody('Hello, this is a simple test going on here...'); $sent = $mailer->send($message); print_r($logger->dump());
GO with the custom mysmtp package, where I just set InsecureSkipVerify: true in the tls configuration to avoid certificate errors, but the return path is incorrect:
hostname := "" username := "" password := "" returnPath := "" subject := "GO sending, test return path" toEmail := "" body := "Hello, this is a simple test going on here..." auth := mysmtp.PlainAuth( "", username, password, hostname, ) header := make(map[string]string) header["Return-Path"] = returnPath header["From"] = username header["To"] = toEmail header["Subject"] = subject message := "" for k, v := range header { message += fmt.Sprintf("%s: %s\r\n", k, v) } message += "\r\n" + string([]byte(body)) err := mysmtp.SendMail( fmt.Sprintf("%s:%d", hostname, 25), auth, username, []string{toEmail}, []byte(message), ) log.Fatal(err)
I literally donβt know what is happening and why this last test was conducted against postfix mta, where I just removed the reject_sender_login_mismatch policy from the postfix configuration to allow this behavior.