title: Debugging SMTP connection
body: <p>I use go's <code>net/smtp</code> to send emails, and it works fine for some emails but not for others. I get an <code>554 5.5.1 Error: no valid recipients</code> but I am pretty sure I give the correct mail address. </p>
  
  <p>(The ultimate goal is to make the <code>net/smtp</code> work for all mail recipients. So answers on that are welcome as well)</p>
  
  <p>How can I debug what's going on in the background? What commands are sent to and from the SMTP server? I'd like to replay the commands from the command line (telnet) to get find out more about the error.</p>
  
  <p>This is the code I use (<a href="http://code.google.com/p/go-wiki/wiki/SendingMail" rel="nofollow">from the go-wiki</a>):</p>
  
  <pre><code>package main
  
  import (
          "bytes"
          "log"
          "net/smtp"
  )
  
  func main() {
          // Connect to the remote SMTP server.
          c, err := smtp.Dial("mail.example.com:25")
          if err != nil {
                  log.Fatal(err)
          }
          // Set the sender and recipient.
          c.Mail("sender@example.org")
          c.Rcpt("recipient@example.net")
          // Send the email body.
          wc, err := c.Data()
          if err != nil {
                  log.Fatal(err)
          }
          defer wc.Close()
          buf := bytes.NewBufferString("This is the email body.")
          if _, err = buf.WriteTo(wc); err != nil {
                  log.Fatal(err)
          }
  }
  </code></pre>
  
  <p>I know this is a very vague question, but any help is much appreciated.</p>