Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "log"
  5. "net/smtp"
  6. "flag"
  7. "fmt"
  8. "os"
  9. )
  10.  
  11. func main() {
  12. // ${0} [flags] <sender> <recipient>
  13. // flags and arguments
  14. server := flag.String("server", "mail.example.com", "The SMTP server to test.")
  15. serverPort := flag.Int("port", 25, "The SMTP port to use")
  16.  
  17. username := flag.String("user", "", "The SMTP username")
  18. password := flag.String("password", "", "The SMTP user's password")
  19.  
  20. flag.Parse()
  21.  
  22. args := flag.Args()
  23.  
  24. if len(args) < 2 {
  25. fmt.Fprint(os.Stderr, "Usage: mail [flags] <sender> <recipient>")
  26. os.Exit(1)
  27. }
  28. // Set up authentication information.
  29. auth := smtp.PlainAuth(
  30. "",
  31. *username,
  32. *password,
  33. *server,
  34. )
  35. // Connect to the server, authenticate, set the sender and recipient,
  36. // and send the email all in one step.
  37. err := smtp.SendMail(
  38. fmt.Sprint(*server, ":", *serverPort),
  39. auth,
  40. args[0],
  41. []string{args[1]},
  42. []byte("This is a test mail."),
  43. )
  44. if err != nil {
  45. log.Fatal(err)
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement