-
Notifications
You must be signed in to change notification settings - Fork 0
/
testEmailConnection.go
47 lines (39 loc) · 1.07 KB
/
testEmailConnection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"sync"
"github.com/emersion/go-imap/client"
)
func testEmailAuthentication(emails []UsersSctruct, Source SourceAddressDTO, results chan<- EmailAuthResult) {
var wg sync.WaitGroup
for _, email := range emails {
wg.Add(1)
go func(e UsersSctruct) {
defer wg.Done()
c := &client.Client{}
if Source.TLS {
clientTLS, err := client.DialTLS(Source.Address, nil)
if err != nil {
results <- EmailAuthResult{Email: e.Username + "@" + Source.Domain, AuthError: err}
return
}
c = clientTLS
} else {
clientNoTLS, err := client.Dial(Source.Address)
if err != nil {
results <- EmailAuthResult{Email: e.Username + "@" + Source.Domain, AuthError: err}
return
}
c = clientNoTLS
}
defer c.Logout()
err := c.Login(e.Username+"@"+Source.Domain, e.Password)
if err != nil {
results <- EmailAuthResult{Email: e.Username + "@" + Source.Domain, AuthError: err}
return
}
results <- EmailAuthResult{Email: e.Username + "@" + Source.Domain, AuthError: err}
}(email)
}
wg.Wait()
close(results)
}