diff --git a/export.go b/export.go index fd1c3dd..6ce31e3 100644 --- a/export.go +++ b/export.go @@ -126,7 +126,11 @@ func (w *messageWriter) addFiles(files []*File, isAttachment bool) { h["Content-Disposition"] = []string{"attachment; filename=\"" + f.Name + "\""} } else { h["Content-Disposition"] = []string{"inline; filename=\"" + f.Name + "\""} - h["Content-ID"] = []string{"<" + f.Name + ">"} + if f.ContentID != "" { + h["Content-ID"] = []string{"<" + f.ContentID + ">"} + } else { + h["Content-ID"] = []string{"<" + f.Name + ">"} + } } w.write(h, f.Content, Base64) diff --git a/gomail.go b/gomail.go index 2a58ece..bb70e97 100644 --- a/gomail.go +++ b/gomail.go @@ -208,9 +208,10 @@ func (msg *Message) GetBodyWriter(contentType string) io.Writer { // A File represents a file that can be attached or embedded in an email. type File struct { - Name string - MimeType string - Content []byte + Name string + MimeType string + Content []byte + ContentID string } // OpenFile opens a file on disk to create a gomail.File. diff --git a/gomail_test.go b/gomail_test.go index 41b4864..d03b9fb 100644 --- a/gomail_test.go +++ b/gomail_test.go @@ -336,7 +336,9 @@ func TestEmbedded(t *testing.T) { msg := NewMessage() msg.SetHeader("From", "from@example.com") msg.SetHeader("To", "to@example.com") - msg.Embed(CreateFile("image1.jpg", []byte("Content 1"))) + f := CreateFile("image1.jpg", []byte("Content 1")) + f.ContentID = "test-content-id" + msg.Embed(f) msg.Embed(CreateFile("image2.jpg", []byte("Content 2"))) msg.SetBody("text/plain", "Test") @@ -355,7 +357,7 @@ func TestEmbedded(t *testing.T) { "--_BOUNDARY_1_\r\n" + "Content-Type: image/jpeg; name=\"image1.jpg\"\r\n" + "Content-Disposition: inline; filename=\"image1.jpg\"\r\n" + - "Content-ID: \r\n" + + "Content-ID: \r\n" + "Content-Transfer-Encoding: base64\r\n" + "\r\n" + base64.StdEncoding.EncodeToString([]byte("Content 1")) + "\r\n" +