Update smtp.go
Showing
1 changed file
with
4 additions
and
2 deletions
| ... | @@ -34,6 +34,7 @@ type SmtpWriter struct { | ... | @@ -34,6 +34,7 @@ type SmtpWriter struct { |
| 34 | Password string `json:"password"` | 34 | Password string `json:"password"` |
| 35 | Host string `json:"Host"` | 35 | Host string `json:"Host"` |
| 36 | Subject string `json:"subject"` | 36 | Subject string `json:"subject"` |
| 37 | FromAddress string `json:"fromAddress" | ||
| 37 | RecipientAddresses []string `json:"sendTos"` | 38 | RecipientAddresses []string `json:"sendTos"` |
| 38 | Level int `json:"level"` | 39 | Level int `json:"level"` |
| 39 | } | 40 | } |
| ... | @@ -50,6 +51,7 @@ func NewSmtpWriter() LoggerInterface { | ... | @@ -50,6 +51,7 @@ func NewSmtpWriter() LoggerInterface { |
| 50 | // "password:"password", | 51 | // "password:"password", |
| 51 | // "host":"smtp.gmail.com:465", | 52 | // "host":"smtp.gmail.com:465", |
| 52 | // "subject":"email title", | 53 | // "subject":"email title", |
| 54 | // "fromAddress":"from@example.com", | ||
| 53 | // "sendTos":["email1","email2"], | 55 | // "sendTos":["email1","email2"], |
| 54 | // "level":LevelError | 56 | // "level":LevelError |
| 55 | // } | 57 | // } |
| ... | @@ -141,10 +143,10 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error { | ... | @@ -141,10 +143,10 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error { |
| 141 | // Connect to the server, authenticate, set the sender and recipient, | 143 | // Connect to the server, authenticate, set the sender and recipient, |
| 142 | // and send the email all in one step. | 144 | // and send the email all in one step. |
| 143 | content_type := "Content-Type: text/plain" + "; charset=UTF-8" | 145 | content_type := "Content-Type: text/plain" + "; charset=UTF-8" |
| 144 | mailmsg := []byte("To: " + strings.Join(s.RecipientAddresses, ";") + "\r\nFrom: " + s.Username + "<" + s.Username + | 146 | mailmsg := []byte("To: " + strings.Join(s.RecipientAddresses, ";") + "\r\nFrom: " + s.FromAddress + "<" + s.FromAddress + |
| 145 | ">\r\nSubject: " + s.Subject + "\r\n" + content_type + "\r\n\r\n" + fmt.Sprintf(".%s", time.Now().Format("2006-01-02 15:04:05")) + msg) | 147 | ">\r\nSubject: " + s.Subject + "\r\n" + content_type + "\r\n\r\n" + fmt.Sprintf(".%s", time.Now().Format("2006-01-02 15:04:05")) + msg) |
| 146 | 148 | ||
| 147 | err := s.sendMail(s.Host, auth, s.Username, s.RecipientAddresses, mailmsg) | 149 | err := s.sendMail(s.Host, auth, s.FromAddress, s.RecipientAddresses, mailmsg) |
| 148 | 150 | ||
| 149 | return err | 151 | return err |
| 150 | } | 152 | } | ... | ... |
-
Please register or sign in to post a comment