MCPcopy Index your code
hub / github.com/jordan-wright/email / Send

Method Send

pool.go:281–327  ·  view source on GitHub ↗

Send sends an email via a connection pulled from the Pool. The timeout may be <0 to indicate no timeout. Otherwise reaching the timeout will produce and error building a connection that occurred while we were waiting, or otherwise ErrTimeout.

(e *Email, timeout time.Duration)

Source from the content-addressed store, hash-verified

279// and error building a connection that occurred while we were waiting, or
280// otherwise ErrTimeout.
281func (p *Pool) Send(e *Email, timeout time.Duration) (err error) {
282 start := time.Now()
283 c := p.get(timeout)
284 if c == nil {
285 return p.failedToGet(start)
286 }
287
288 defer func() {
289 p.maybeReplace(err, c)
290 }()
291
292 recipients, err := addressLists(e.To, e.Cc, e.Bcc)
293 if err != nil {
294 return
295 }
296
297 msg, err := e.Bytes()
298 if err != nil {
299 return
300 }
301
302 from, err := emailOnly(e.From)
303 if err != nil {
304 return
305 }
306 if err = c.Mail(from); err != nil {
307 return
308 }
309
310 for _, recip := range recipients {
311 if err = c.Rcpt(recip); err != nil {
312 return
313 }
314 }
315
316 w, err := c.Data()
317 if err != nil {
318 return
319 }
320 if _, err = w.Write(msg); err != nil {
321 return
322 }
323
324 err = w.Close()
325
326 return
327}
328
329func emailOnly(full string) (string, error) {
330 addr, err := mail.ParseAddress(full)

Callers

nothing calls this directly

Calls 7

getMethod · 0.95
failedToGetMethod · 0.95
maybeReplaceMethod · 0.95
addressListsFunction · 0.85
emailOnlyFunction · 0.85
BytesMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected