Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | //////////////////////////////////////////////////////////////////////////////// |
||
7 | package email |
||
8 | |||
9 | import ( |
||
10 | "github.com/mylockerteam/mailSender" |
||
11 | "gopkg.in/gomail.v2" |
||
12 | "html/template" |
||
13 | "io" |
||
14 | ) |
||
15 | |||
16 | // Strategy logging strategy in the email |
||
17 | // You can use it for errors and other types of messages |
||
18 | type Strategy struct { |
||
19 | sender mailSender.AsyncSender |
||
20 | Message *gomail.Message |
||
21 | Template *template.Template |
||
22 | io.Writer |
||
23 | } |
||
24 | |||
25 | //Get waiting for a parameter ess in format host:port;username;password |
||
26 | func Get(sender mailSender.AsyncSender, msg *gomail.Message, tpl *template.Template) io.Writer { |
||
27 | return &Strategy{ |
||
28 | sender: sender, |
||
29 | Message: msg, |
||
30 | Template: tpl, |
||
31 | } |
||
32 | } |
||
33 | |||
34 | func (s *Strategy) Write(p []byte) (n int, err error) { |
||
35 | s.sender.SendAsync(mailSender.Message{ |
||
36 | Message: s.Message, |
||
37 | Template: s.Template, |
||
38 | Data: mailSender.EmailData{"Data": string(p)}, |
||
39 | }) |
||
40 | return len(p), nil |
||
41 | } |
||
42 |