smtp_auth.go 730 B

1234567891011121314151617181920212223242526272829
  1. // smtp_auth.go
  2. package main
  3. import (
  4. "log"
  5. "net/smtp"
  6. )
  7. func main() {
  8. // Set up authentication information.
  9. auth := smtp.PlainAuth(
  10. "",
  11. "[email protected]",
  12. "password",
  13. "mail.example.com",
  14. )
  15. // Connect to the server, authenticate, set the sender and recipient,
  16. // and send the email all in one step.
  17. err := smtp.SendMail(
  18. "mail.example.com:25",
  19. auth,
  20. "[email protected]",
  21. []string{"[email protected]"},
  22. []byte("This is the email body."),
  23. )
  24. if err != nil {
  25. log.Fatal(err)
  26. }
  27. }