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")
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效