Fixing multiple multipart attachments for text and html parts. Not needed
1 files changed, 9 insertions(+), 6 deletions(-)

M message.go
M message.go +9 -6
@@ 104,6 104,7 @@ type Message struct {
 
 	mb       bytes.Buffer
 	mw       *mail.Writer
+	tw       *mail.InlineWriter
 	once     sync.Once
 	isClosed bool
 

          
@@ 231,25 232,26 @@ func (m *Message) openWriter() {
 				panic(err)
 			}
 		}
+
+		m.tw, err = m.mw.CreateInline()
+		if err != nil {
+			panic(err)
+		}
 	})
 }
 
 func (m *Message) createInline(ctype string, data io.Reader) error {
 	m.openWriter()
-	tw, err := m.mw.CreateInline()
-	if err != nil {
-		return err
-	}
 
 	var th mail.InlineHeader
 	th.Set("Content-Type", ctype)
-	w, err := tw.CreatePart(th)
+	w, err := m.tw.CreatePart(th)
 	if err != nil {
 		return err
 	}
 
 	// Last in, first out
-	defer tw.Close()
+	// defer tw.Close()
 	defer w.Close()
 
 	if _, err = io.Copy(w, data); err != nil {

          
@@ 321,6 323,7 @@ func (m *Message) GetAllRcpts() []string
 // Close Closes the mail.Writer
 func (m *Message) Close() {
 	if m.mw != nil && !m.isClosed {
+		m.tw.Close()
 		m.mw.Close()
 		if m.ct != nil {
 			m.ct.Close()