Matias Barrios
Matias Barrios

Reputation: 5056

Mail server with Golang

I have a valid mail server, with SSL certificates, DNS and PTR records and an overall secure configuration.

I am able to send mails from the terminal using sendmail tool. But when I try with this code :

package main

import (
        "fmt"
        "net/smtp"
)

func main(){
        err := smtp.SendMail("localhost:25",nil, "[email protected]", []string {"[email protected]"}, []byte("This is a test form golang"))
        if err != nil {
                fmt.Println(err.Error())
        }
}

I get the following error :

x509: certificate is valid for mydomain.com, not localhost

What should I change in my code ( or in the server config ) to be able to send mails from my code.

Upvotes: 1

Views: 3112

Answers (1)

Oppen
Oppen

Reputation: 433

The source of the error is that, for security reasons, the involved parties expect hostnames to match the ones in the certificate. sendmail is probably not checking certificates (I haven't found mention greping the manpage).

The solution is to connect to the server using the proper domain name, or for testing to create a certificate that matches the domain name localhost.

Upvotes: 1

Related Questions