O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter07/recipe10.
  2. Navigate to the directory.
  3. Create the smtp.go file with the following content:
        package main        import (          "crypto/tls"          "fmt"          "net/smtp"        )        func main() {          var email string          fmt.Println("Enter username for smtp: ")          fmt.Scanln(&email)          var pass string          fmt.Println("Enter password for smtp: ")          fmt.Scanln(&pass)          auth := smtp.PlainAuth("", email, pass, "smtp.gmail.com")          c, err := smtp.Dial("smtp.gmail.com:587")          if err != nil {            panic(err)          }          defer c.Close()          config := &tls.Config{ServerName: "smtp.gmail.com"}          if err = c.StartTLS(config); err != nil {            panic(err)          }          if err = c.Auth(auth); err != nil {            panic(err)          }          if err = c.Mail(email); err != nil {            panic(err)          } if err = c.Rcpt(email); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required