src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

auth.go (584B)


      1 package gmail
      2 
      3 import (
      4 	"fmt"
      5 	"net/smtp"
      6 )
      7 
      8 const Address = "smtp.gmail.com:587"
      9 
     10 type Auth struct {
     11 	Username string
     12 	Password string
     13 }
     14 
     15 func (a *Auth) Start(server *smtp.ServerInfo) (string, []byte, error) {
     16 	return "LOGIN", []byte{}, nil
     17 }
     18 
     19 func (a *Auth) Next(fromServer []byte, more bool) ([]byte, error) {
     20 	if more {
     21 		fs := string(fromServer)
     22 
     23 		switch fs {
     24 		case "Username:":
     25 			return []byte(a.Username), nil
     26 		case "Password:":
     27 			return []byte(a.Password), nil
     28 		default:
     29 			return nil, fmt.Errorf(
     30 				"unrecognized fromServer: %s", fs,
     31 			)
     32 		}
     33 	}
     34 
     35 	return nil, nil
     36 }