MCPcopy Create free account
hub / github.com/apache/answer / Send

Method Send

internal/service/export/email_service.go:123–157  ·  view source on GitHub ↗

Send email send

(ctx context.Context, toEmailAddr, subject, body string)

Source from the content-addressed store, hash-verified

121
122// Send email send
123func (es *EmailService) Send(ctx context.Context, toEmailAddr, subject, body string) {
124 log.Infof("try to send email to %s", toEmailAddr)
125 ec, err := es.GetEmailConfig(ctx)
126 if err != nil {
127 log.Errorf("get email config failed: %s", err)
128 return
129 }
130 if len(ec.SMTPHost) == 0 {
131 log.Warnf("smtp host is empty, skip send email")
132 return
133 }
134
135 m := gomail.NewMessage()
136 fromName := mime.QEncoding.Encode("utf-8", ec.FromName)
137 m.SetHeader("From", fmt.Sprintf("%s <%s>", fromName, ec.FromEmail))
138 m.SetHeader("To", toEmailAddr)
139 m.SetHeader("Subject", subject)
140 m.SetBody("text/html", body)
141
142 d := gomail.NewDialer(ec.SMTPHost, ec.SMTPPort, ec.SMTPUsername, ec.SMTPPassword)
143 if ec.IsSSL() {
144 d.SSL = true
145 }
146 if ec.IsTLS() {
147 d.SSL = false
148 }
149 if len(os.Getenv("SKIP_SMTP_TLS_VERIFY")) > 0 {
150 d.TLSConfig = &tls.Config{ServerName: d.Host, InsecureSkipVerify: true}
151 }
152 if err := d.DialAndSend(m); err != nil {
153 log.Errorf("send email to %s failed: %s", toEmailAddr, err)
154 } else {
155 log.Infof("send email to %s success", toEmailAddr)
156 }
157}
158
159// VerifyUrlExpired email send
160func (es *EmailService) VerifyUrlExpired(ctx context.Context, code string) (content string) {

Callers 2

SendAndSaveCodeMethod · 0.95

Calls 3

GetEmailConfigMethod · 0.95
IsSSLMethod · 0.80
IsTLSMethod · 0.80

Tested by

no test coverage detected