(to, cc, bcc []string, from, subject, body string, attachments []string)
| 66 | ) |
| 67 | |
| 68 | func sendSMTPEmail(to, cc, bcc []string, from, subject, body string, attachments []string) error { |
| 69 | server := mail.NewSMTPClient() |
| 70 | |
| 71 | var err error |
| 72 | server.Username = smtpUsername |
| 73 | server.Password = smtpPassword |
| 74 | server.Host = smtpHost |
| 75 | server.Port = smtpPort |
| 76 | |
| 77 | // Set defaults for gmail. |
| 78 | if strings.HasSuffix(server.Username, gmailSuffix) { |
| 79 | if server.Port == 0 { |
| 80 | server.Port = gmailSMTPPort |
| 81 | } |
| 82 | if server.Host == "" { |
| 83 | server.Host = gmailSMTPHost |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | switch strings.ToLower(smtpEncryption) { |
| 88 | case "ssl": |
| 89 | server.Encryption = mail.EncryptionSSLTLS |
| 90 | case "none": |
| 91 | server.Encryption = mail.EncryptionNone |
| 92 | default: |
| 93 | server.Encryption = mail.EncryptionSTARTTLS |
| 94 | } |
| 95 | |
| 96 | server.KeepAlive = false |
| 97 | server.ConnectTimeout = 10 * time.Second |
| 98 | server.SendTimeout = 10 * time.Second |
| 99 | server.TLSConfig = &tls.Config{ |
| 100 | InsecureSkipVerify: smtpInsecureSkipVerify, //nolint:gosec |
| 101 | ServerName: server.Host, |
| 102 | } |
| 103 | |
| 104 | smtpClient, err := server.Connect() |
| 105 | if err != nil { |
| 106 | return fmt.Errorf("connecting to SMTP server: %w", err) |
| 107 | } |
| 108 | |
| 109 | email := mail.NewMSG() |
| 110 | email.SetFrom(from). |
| 111 | AddTo(to...). |
| 112 | AddCc(cc...). |
| 113 | AddBcc(bcc...). |
| 114 | SetSubject(subject) |
| 115 | |
| 116 | html := bytes.NewBufferString("") |
| 117 | convertErr := goldmark.Convert([]byte(body), html) |
| 118 | |
| 119 | if convertErr != nil { |
| 120 | email.SetBody(mail.TextPlain, body) |
| 121 | } else { |
| 122 | email.SetBody(mail.TextHTML, html.String()) |
| 123 | } |
| 124 | |
| 125 | for _, a := range attachments { |
no outgoing calls
no test coverage detected