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)
| 279 | // and error building a connection that occurred while we were waiting, or |
| 280 | // otherwise ErrTimeout. |
| 281 | func (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 | |
| 329 | func emailOnly(full string) (string, error) { |
| 330 | addr, err := mail.ParseAddress(full) |
nothing calls this directly
no test coverage detected