Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gomail: could not send email 1: 502 5.3.3 Command not implemented #205

Open
lvjianzhao opened this issue Feb 26, 2025 · 2 comments
Open

Comments

@lvjianzhao
Copy link

When I use go 1.16, I get an error:

2025/02/26 19:10:27 邮件发送失败:gomail: could not send email 1: 502 5.3.3 Command not implemented
exit status 1

When I use go 1.15, I can send normally:

$ g use 1.15
go version go1.15 windows/amd64
$ go run main.go
邮件发送成功!

My code is as follows:

package main

import (
    "fmt"
    "gopkg.in/gomail.v2"
    "log"
    "crypto/tls"
)

func SendEmail() {
    // 邮件内容
    from := "[email protected]"  // 发件人邮箱
    password := "xxxxxxxxx" // 发件人邮箱密码
    to := "[email protected]" // 收件人邮箱
    subject := "邮件发送测试"
    body := "这是一个简单的邮件测试内容xxaaa!"

    // 创建邮件对象
    m := gomail.NewMessage()

    // 设置发件人、收件人和邮件主题
    m.SetHeader("From", from)
    m.SetHeader("To", to)
    m.SetHeader("Subject", subject)

    // 设置邮件内容
    m.SetBody("text/plain", body)

    // 创建SMTP客户端
    d := gomail.NewDialer("email.xxxx.com", 25, from, password)


    d.TLSConfig = &tls.Config{InsecureSkipVerify: true}

    // 发送邮件
    if err := d.DialAndSend(m); err != nil {
        log.Fatal("邮件发送失败:", err)
    } else {
        fmt.Println("邮件发送成功!")
    }
}

func main() {
    SendEmail()
}

What is the reason?

@wneessen
Copy link

That's hard to tell without seeing the communication between the client and the server. The client is sending something that the server does not like/supports. The only thing I can see that has been changed in net/smtp between v1.15 and v1.16 is the addition of SMTPUTF8 support but I do not think that this might cause the issue. In any case 1.15 and 1.16 are very old versions of Go. You might want to update to a newer version to not run into security vulnerabilities.

That being said, this package is not maintained anymore since the author sadly passed away. You can have a go with go-mail which supports debug logging. It can show you the communication between the client and the server, which might shed some light into what exactly the server doesn't like.

@lvjianzhao
Copy link
Author

@wneessen Thank you for your reply. I will try go-mail later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants