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

Method AttachFile

email.go:282–292  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
282func (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

Callers 1

ExampleAttachFunction · 0.95

Calls 2

AttachMethod · 0.95
CloseMethod · 0.45

Tested by 1

ExampleAttachFunction · 0.76