gpt4 book ai didi

gomail noauth 示例崩溃

转载 作者:数据小太阳 更新时间:2023-10-29 03:35:37 24 4
gpt4 key购买 nike

我正在尝试关注 this example :

package main

import (
"gopkg.in/gomail.v2"
)




func main() {
m := gomail.NewMessage()
m.SetHeader("From", "from@example.com")
m.SetHeader("To", "to@example.com")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/plain", "Hello!")

d := gomail.Dialer{Host: "localhost", Port: 587}
if err := d.DialAndSend(m); err != nil {
panic(err)
}
} //main

我得到了这个错误:

panic: 454 4.7.0 TLS not available due to local problem

goroutine 1 [running]:
panic(0x244ca0, 0xc820010b20)
/usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
main.main()
/Users/kaiyin/IdeaProjects/gomail/main.go:19 +0x342
exit status 2

我还尝试禁用 TLS 和 SSL:

    d := gomail.Dialer{Host: "localhost", Port: 587, SSL: false, TLSConfig: nil}

但错误仍然存​​在。


我查看了 mail.log(来自 osx 10.10 上的 postfix):

Apr  7 14:28:05 kaiyins-mbp postfix/smtpd[64525]: warning: No server certs available. TLS won't be enabled
Apr 7 14:28:05 kaiyins-mbp postfix/smtpd[64525]: connect from localhost[::1]
Apr 7 14:28:05 kaiyins-mbp postfix/smtpd[64525]: lost connection after STARTTLS from localhost[::1]

所以我生成了这样的证书:

cd /etc/postfix
sudo openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509

并更改后缀设置:

smtpd_enforce_tls                = no
smtpd_tls_loglevel = 1
smtpd_use_tls = yes
smtpd_tls_key_file = /etc/postfix/smtpd.key
smtpd_tls_cert_file = /etc/postfix/smtpd.cert

现在我得到一个不同的错误:

panic: x509: certificate signed by unknown authority

goroutine 1 [running]:
panic(0x26e3c0, 0xc8203e4b80)
/usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
main.main()
/Users/kaiyin/IdeaProjects/gomail/main.go:19 +0x32f
exit status 2

我尝试按照此处的说明生成证书:http://www.akadia.com/services/ssh_test_certificate.html

我又遇到了另一个错误:

panic: x509: certificate is valid for Kaiyin Zhong, not localhost

goroutine 1 [running]:
panic(0x26a7e0, 0xc8203e6800)
/usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
main.main()
/Users/kaiyin/IdeaProjects/gomail/main.go:19 +0x32f
exit status 2

我以为我弄错了服务器名称,所以我重新做了一遍,将服务器 FQDN 设置为 localhost:

Common Name (e.g. server FQDN or YOUR name) []:localhost

然后又回到了之前的错误:

panic: x509: certificate signed by unknown authority

goroutine 1 [running]:
panic(0x26e3c0, 0xc8203e6800)
/usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:464 +0x3e6
main.main()
/Users/kaiyin/IdeaProjects/gomail/main.go:19 +0x32f
exit status 2

最佳答案

设置 InsecureSkipVerify 选项:

package main

import (
"crypto/tls"

"gopkg.in/gomail.v2"
)

func main() {
d := gomail.NewDialer("smtp.example.com", 587, "user", "123456")
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}

// Send emails using d.
}

来源:https://github.com/go-gomail/gomail

关于gomail noauth 示例崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36476601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com