MCPcopy
hub / github.com/charmbracelet/pop / sendSMTPEmail

Function sendSMTPEmail

email.go:68–133  ·  view source on GitHub ↗
(to, cc, bcc []string, from, subject, body string, attachments []string)

Source from the content-addressed store, hash-verified

66)
67
68func 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 {

Callers 2

sendEmailCmdMethod · 0.85
main.goFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected