Answer the question
In order to leave comments, you need to log in
Why does it give an error when sending a letter?
Why does it give an error " wrong host name "? Same for https://smtp.mail.ru:25 and smtp.mail.ru:25 . The host is copied from a working email.
from := os.Getenv("[email protected]")
password := os.Getenv("myPass")
toList := []string{"[email protected]"}
host := "https://smtp.mail.ru:25"
bodyMsg := []byte("Hello geeks!!!")
auth := smtp.PlainAuth("", from, password, host)
err := smtp.SendMail(host, auth, from, toList, bodyMsg)
Answer the question
In order to leave comments, you need to log in
I suspect that the error is in this line, you specify the port (: 25), you need to remove it.
// у вас host = "https://smtp.mail.ru:25", а должен быть "smtp.mail.ru"
auth := smtp.PlainAuth("", from, password, host)
import (
"log"
"net/smtp"
)
func main() {
// Set up authentication information.
// тут порт не указан, скорее всего ругается именно в этой строке
auth := smtp.PlainAuth("", "[email protected]", "password", "mail.example.com")
// Connect to the server, authenticate, set the sender and recipient,
// and send the email all in one step.
to := []string{"[email protected]"}
msg := []byte("To: [email protected]\r\n" +
"Subject: discount Gophers!\r\n" +
"\r\n" +
"This is the email body.\r\n")
// тут порт указан, т.е. host:port, но не указывается протокол типа https, тут протокол SMTP
err := smtp.SendMail("mail.example.com:25", auth, "[email protected]", to, msg)
if err != nil {
log.Fatal(err)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question