gpt4 book ai didi

go - 如何向服务器发送自定义问候语

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

我尝试在 Go 中创建一个 SMTP 发件人。这是代码的一部分:

client, err := smtp.NewClient(remote, smtpServer.Host)
if err != nil {
return err
}
defer client.Close()

auth := SmtpLoginAuth(smtpServer.Username, smtpServer.Password)
authErr := client.Auth(auth)
if authErr != nil {
fmt.Println("login error", authErr)
return authErr
}


client.Mail(data.From())
client.Rcpt(data.To())
bodyWriter, err := client.Data()
if err != nil {
fmt.Println("body error", err)
return err
}

我的问题是:我想更改服务器的问候消息,此刻我的应用程序从本地主机发送,我想发送我服务器的 DNS 域,但我不知道如何在 go 中执行此操作。

我想更改本地主机字符串的示例位置:https://jmp.sh/sugc8Ax

最佳答案

设置 EHLO/HELO 命令中使用的名称可以简单地通过 Hello(name) 完成。来自 the documentation :

func (c *Client) Hello(localName string) error
Hello sends a HELO or EHLO to the server as the given host name. Calling this method is only necessary if the client needs control over the host name used. The client will introduce itself as "localhost" automatically otherwise. If Hello is called, it must be called before any of the other methods.

因此,您需要做的就是这样:

client, err := smtp.NewClient(remote, smtpServer.Host)
...
client.Hello("foobar.example.com")

关于go - 如何向服务器发送自定义问候语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52012522/

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