parent
de623e612d
commit
6805982221
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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: <image1.jpg>\r\n" +
|
||||
"Content-ID: <test-content-id>\r\n" +
|
||||
"Content-Transfer-Encoding: base64\r\n" +
|
||||
"\r\n" +
|
||||
base64.StdEncoding.EncodeToString([]byte("Content 1")) + "\r\n" +
|
||||
|
|
Loading…
Reference in New Issue