I have a website using Golang as “Apache”.
http.ListenAndServe(“:9090”, nil) <----- starts the website
In this website I have a form that I submit a mail using smtp.SendMail.
-
Sending a “valid” mail address works perfect
-
Sending a “valid” mail address sometimes returns “550 5.7.1 SPF failed. Domain test.com is not allowed to send mail from (IP-address)”
-
Sending a “nonsense” mail address (test) fails and report “501 5.1.7 Bad sender address syntax”
mailfrom = "test@company.se" <--- VALID mail address auth := smtp.PlainAuth("", "sibert@gmail.com", "password", "smtp.gmail.com") from := (mailfrom) to := []string{"sibert@gmail.com"} msg := []byte("From: " + mailfrom + "\r\n" + "To: support@company.com\r\n" + "Subject: Test\r\n" + "testmail\r\n" + (mailfrom)) err := smtp.SendMail("smtp.gmail.com:587", auth, from, to, msg) if err != nil { log.Fatal(err) } }
There is two problem:
- How can I trap this and send “sorry not delivered” to the user?
- How can I prevent “http.ListenAndServe” to crash when Go do not like the mail address?