11package emailservice
22
33import (
4+ "crypto/tls"
45 "errors"
56 "net/smtp"
67 "os"
78 "strconv"
8- "time"
99
1010 "github.com/apex/log"
1111 "github.com/jordan-wright/email"
@@ -76,17 +76,12 @@ func Setup(conf EmailServerConfiguration, onMailSend func(err error)) error {
7676
7777 poolSize := 4
7878
79- p , err := email .NewPool (
80- conf .Host + ":" + conf .Port ,
81- poolSize ,
82- smtp .PlainAuth (conf .Identity , conf .Username , conf .Password , conf .Host ),
83- )
84- if err != nil {
85- return err
86- }
79+ auth := smtp .PlainAuth (conf .Identity , conf .Username , conf .Password , conf .Host )
80+ tlsConfig := tls.Config {ServerName : conf .Host }
81+ address := conf .Host + ":" + conf .Port
8782
8883 for i := 0 ; i < poolSize ; i ++ {
89- go func (from string ) {
84+ go func (from string , auth smtp. Auth , tlsConfig tls. Config , address string ) {
9085 for e := range ch {
9186 retryCount := 0
9287 for retryCount < 4 {
@@ -97,7 +92,8 @@ func Setup(conf EmailServerConfiguration, onMailSend func(err error)) error {
9792 }
9893
9994 e .From = from
100- err := p .Send (e , 10 * time .Second )
95+
96+ err := e .SendWithStartTLS (address , auth , & tlsConfig )
10197 if onMailSend != nil {
10298 onMailSend (err )
10399 }
@@ -109,7 +105,7 @@ func Setup(conf EmailServerConfiguration, onMailSend func(err error)) error {
109105 retryCount ++
110106 }
111107 }
112- }(conf .From )
108+ }(conf .From , auth , tlsConfig , address )
113109 }
114110
115111 log .Info ("Email service running.." )
0 commit comments