Skip to content

Commit

Permalink
Fixed email attachment/inline
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <vr@labstack.com>
  • Loading branch information
vishr committed Jul 12, 2017
1 parent bf40841 commit 779b8a8
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"crypto/tls"
"html/template"
"mime/quotedprintable"
"net/mail"
"net/smtp"

Expand Down Expand Up @@ -67,22 +66,21 @@ func (m *Message) writeBoundary() {
func (m *Message) writeText(content string, contentType string) {
m.writeBoundary()
m.writeHeader("Content-Type", contentType+"; charset=UTF-8")
m.writeHeader("Content-Transfer-Encoding", "quoted-printable")
m.buffer.WriteString("\r\n")
qp := quotedprintable.NewWriter(m.buffer)
defer qp.Close()
qp.Write([]byte(content))
m.buffer.WriteString(content)
m.buffer.WriteString("\r\n")
m.buffer.WriteString("\r\n")
}

func (m *Message) writeFile(f *File, disposition string) {
m.writeBoundary()
m.writeHeader("Content-Type", f.Type+"; name="+f.Name)
m.writeHeader("Content-Disposition", disposition+"; filename="+f.Name)
m.writeHeader("Content-Type", f.Type+`; name="`+f.Name+`"`)
m.writeHeader("Content-Disposition", disposition+`; filename="`+f.Name+`"`)
m.writeHeader("Content-Transfer-Encoding", "base64")
m.buffer.WriteString("\r\n")
m.buffer.WriteString(f.Content)
m.buffer.WriteString("\r\n")
m.buffer.WriteString("\r\n")
}

func (e *Email) Send(m *Message) (err error) {
Expand Down Expand Up @@ -117,14 +115,14 @@ func (e *Email) Send(m *Message) (err error) {
// TODO:
}

// Attachments / inlines
// Inlines/attachments
for _, f := range m.Inlines {
m.writeFile(f, "inline")
}
for _, f := range m.Attachments {
m.writeFile(f, "disposition")
m.writeFile(f, "attachment")
}
m.buffer.WriteString("\r\n\r\n--")
m.buffer.WriteString("--")
m.buffer.WriteString(m.boundary)
m.buffer.WriteString("--")

Expand Down

0 comments on commit 779b8a8

Please sign in to comment.