Reputation: 33
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
Upvotes: 0
Views: 544
Reputation: 123461
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")
Upvotes: 2