diff --git a/msg.go b/msg.go index bc044db..33d7d18 100644 --- a/msg.go +++ b/msg.go @@ -461,7 +461,7 @@ func (m *Msg) Reset() { // Write writes the formated Msg into a give io.Writer func (m *Msg) Write(w io.Writer) (int64, error) { - mw := &msgWriter{w: w} + mw := &msgWriter{w: w, c: m.charset, en: m.encoder} mw.writeMsg(m) return mw.n, mw.err } diff --git a/msgwriter.go b/msgwriter.go index 3d871b3..eb69cee 100644 --- a/msgwriter.go +++ b/msgwriter.go @@ -18,7 +18,9 @@ const MaxHeaderLength = 76 // msgWriter handles the I/O to the io.WriteCloser of the SMTP client type msgWriter struct { + c Charset d int8 + en mime.WordEncoder err error mpw [3]*multipart.Writer n int64 @@ -125,7 +127,8 @@ func (mw *msgWriter) addFiles(fl []*File, a bool) { if mt == "" { mt = "application/octet-stream" } - f.setHeader(HeaderContentType, fmt.Sprintf(`%s; name="%s"`, mt, f.Name)) + f.setHeader(HeaderContentType, fmt.Sprintf(`%s; name="%s"`, mt, + mw.en.Encode(mw.c.String(), f.Name))) } if _, ok := f.getHeader(HeaderContentTransferEnc); !ok { @@ -137,7 +140,8 @@ func (mw *msgWriter) addFiles(fl []*File, a bool) { if a { d = "attachment" } - f.setHeader(HeaderContentDisposition, fmt.Sprintf(`%s; filename="%s"`, d, f.Name)) + f.setHeader(HeaderContentDisposition, fmt.Sprintf(`%s; filename="%s"`, d, + mw.en.Encode(mw.c.String(), f.Name))) } if !a {