Skip to content

Commit 0ede4d8

Browse files
committed
Email fixed message body
Signed-off-by: Vishal Rana <[email protected]>
1 parent 46ded86 commit 0ede4d8

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

email/email.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,30 @@ func (m *Message) writeFile(f *File, disposition string) {
6464
}
6565

6666
func (e *Email) Send(m *Message) error {
67-
// Construct message
6867
m.buffer = new(bytes.Buffer)
6968
m.boundary = random.String(16)
7069
m.buffer.WriteString("MIME-Version: 1.0\r\n")
7170
m.buffer.WriteString(fmt.Sprintf("CC: %s\r\n", m.CC))
7271
m.buffer.WriteString(fmt.Sprintf("Subject: %s\r\n", m.Subject))
7372
m.buffer.WriteString(fmt.Sprintf("Content-Type: multipart/mixed; boundary=%s\r\n", m.boundary))
7473
m.buffer.WriteString("\r\n")
74+
75+
// Message body
7576
if m.TemplateName != "" {
7677
buf := new(bytes.Buffer)
7778
if err := e.Template.ExecuteTemplate(buf, m.TemplateName, m.TemplateData); err != nil {
7879
return err
7980
}
8081
m.writeText(buf.String(), "text/plain")
81-
} else {
82+
} else if m.Text != "" {
8283
m.writeText(m.Text, "text/plain")
84+
} else if m.HTML != "" {
8385
m.writeText(m.HTML, "text/html")
86+
} else {
87+
// TODO:
8488
}
89+
90+
// Attachments / inlines
8591
for _, f := range m.Inlines {
8692
m.writeFile(f, "inline")
8793
}

email/email_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
11
package email
2+
3+
import (
4+
"net/smtp"
5+
"testing"
6+
)
7+
8+
func TestSend(t *testing.T) {
9+
// e := New("smtp.gmail.com:465")
10+
e := New("smtp.elasticemail.com:2525")
11+
// e.Auth = smtp.PlainAuth("", "[email protected]", "Dream1980", "smtp.gmail.com")
12+
e.Auth = smtp.PlainAuth("", "[email protected]", "54643b5b-3284-4f33-89bf-d228951c527f", "smtp.elasticemail.com")
13+
// err := smtp.SendMail("smtp.elasticemail.com:2525", e.Auth, "[email protected]", []string{"[email protected]"}, []byte("body"))
14+
// fmt.Println(err)
15+
e.Send(&Message{
16+
17+
18+
Subject: "test",
19+
Text: "xxxxxxxxxxxxxxxxxxxxxxxxxx",
20+
})
21+
}

0 commit comments

Comments
 (0)