فهرست منبع

Fixed bug in using wrong multipart Writer when sending attachments
Attaching and sending files now works!

Jordan 11 سال پیش
والد
کامیت
99b25f9273
1فایلهای تغییر یافته به همراه2 افزوده شده و 4 حذف شده
  1. 2 4
      email.go

+ 2 - 4
email.go

@@ -62,7 +62,7 @@ func (e *Email) Attach(filename string) (a *Attachment, err error) {
 		//If the Content-Type is blank, set the Content-Type to "application/octet-stream"
 		at.Header.Set("Content-Type", "application/octet-stream")
 	}
-	at.Header.Set("Content-Disposition", fmt.Sprintf("attachment;\r\n filename=%s", filename))
+	at.Header.Set("Content-Disposition", fmt.Sprintf("attachment;\r\n filename=\"%s\"", filename))
 	at.Header.Set("Content-Transfer-Encoding", "base64")
 	return e.Attachments[filename], nil
 }
@@ -125,16 +125,14 @@ func (e *Email) Bytes() ([]byte, error) {
 	}
 	//Create attachment part, if necessary
 	if e.Attachments != nil {
-		subWriter := multipart.NewWriter(buff)
 		for _, a := range e.Attachments {
-			ap, err := subWriter.CreatePart(a.Header)
+			ap, err := w.CreatePart(a.Header)
 			if err != nil {
 				return nil, err
 			}
 			//Write the base64Wrapped content to the part
 			base64Wrap(ap, a.Content)
 		}
-		subWriter.Close()
 	}
 	w.Close()
 	return buff.Bytes(), nil