func (e *emailer) ID() string {
	return providerID
}
ID returns the Provider's ID.
package main
import (
	"encoding/json"
	"errors"
	"fmt"
	"net/smtp"
	"regexp"
	"time"
	"github.com/jordan-wright/email"
	"github.com/knadh/otpgateway/models"
)
const (
	providerID    = "smtp"
	channelName   = "E-mail"
	addressName   = "E-mail ID"
	maxOTPlen     = 6
	maxAddressLen = 100
	maxBodyLen    = 100 * 1024
)
var reMail = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
type cfg struct {
	Host         string `json:"Host"`
	Port         int    `json:"Port"`
	AuthProtocol string `json:"AuthProtocol"`
	User         string `json:"User"`
	Password     string `json:"Password"`
	FromEmail    string `json:"FromEmail"`
	SendTimeout  int    `json:"SendTimeout"`
	MaxConns     int    `json:"MaxConns"`
}
type emailer struct {
	cfg     cfg
	timeout time.Duration
	mailer  *email.Pool
}
func New(jsonCfg []byte) (interface{}, error) {
	var c cfg
	if err := json.Unmarshal(jsonCfg, &c); err != nil {
		return nil, fmt.Errorf("error reading config: %v", err)
	}
	if c.Host == "" {
		c.Host = "127.0.0.1"
	}
	if c.Port == 0 {
		c.Port = 25
	}
	if c.MaxConns == 0 {
		c.MaxConns = 1
	}
	if c.FromEmail == "" {
		c.FromEmail = "otp@localhost"
	}
	var auth smtp.Auth
	if c.AuthProtocol == "cram" {
		auth = smtp.CRAMMD5Auth(c.User, c.Password)
	} else {
		auth = smtp.PlainAuth("", c.User, c.Password, c.Host)
	}
	pool, err := email.NewPool(fmt.Sprintf("%s:%d", c.Host, c.Port), c.MaxConns, auth)
	if err != nil {
		return nil, err
	}
	t := 5
	if c.SendTimeout == 0 {
		t = c.SendTimeout
	}
	return &emailer{
		mailer:  pool,
		cfg:     c,
		timeout: time.Second * time.Duration(t),
	}, nil
}