AttachFile is used to attach content to the email. It attempts to open the file referenced by filename and, if successful, creates an Attachment. This Attachment is then appended to the slice of Email.Attachments. The function will then return the Attachment for reference, as well as nil for the err
(filename string)
| 280 | // This Attachment is then appended to the slice of Email.Attachments. |
| 281 | // The function will then return the Attachment for reference, as well as nil for the error, if successful. |
| 282 | func (e *Email) AttachFile(filename string) (a *Attachment, err error) { |
| 283 | f, err := os.Open(filename) |
| 284 | if err != nil { |
| 285 | return |
| 286 | } |
| 287 | defer f.Close() |
| 288 | |
| 289 | ct := mime.TypeByExtension(filepath.Ext(filename)) |
| 290 | basename := filepath.Base(filename) |
| 291 | return e.Attach(f, basename, ct) |
| 292 | } |
| 293 | |
| 294 | // msgHeaders merges the Email's various fields and custom headers together in a |
| 295 | // standards compliant way to create a MIMEHeader to be used in the resulting |