dozc58418381 2018-08-24 22:41
浏览 25
已采纳

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

I try create an SMTP sender in Go. This is part of code:

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
}

My problem is: I want to change hello message for server, in this moment my app send from localhost, i want to send DNS domain of my server but I don't know how I can do this in go.

example place where I want to change localhost string : https://jmp.sh/sugc8Ax

  • 写回答

1条回答 默认 最新

  • dst2007 2018-08-25 04:14
    关注

    Setting the name used within the EHLO/HELO command can simply be done with Hello(name). From 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.

    Thus, all you need to do is something like this:

    client, err := smtp.NewClient(remote, smtpServer.Host)
    ...
    client.Hello("foobar.example.com")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用