diff --git a/attach.go b/attach.go index 68be9c1..66ddfd7 100644 --- a/attach.go +++ b/attach.go @@ -16,6 +16,8 @@ import ( type File struct { // FilePath is the path of the file to attach. FilePath string + // ContentID is the contentID of the attachment. Optional. Used instead of Name to look up inline attachment in the body if provided. + ContentID string // Name is the name of file in attachment. Required for Data and B64Data. Optional for FilePath. Name string // MimeType of attachment. If empty then is obtained from Name (if not empty) or FilePath. If cannot obtained, application/octet-stream is set. diff --git a/message.go b/message.go index 98c4dfe..2e5b472 100644 --- a/message.go +++ b/message.go @@ -238,7 +238,11 @@ func (msg *message) addFiles(files []*File, inline bool) { header.Set("Content-Transfer-Encoding", encoding.string()) if inline { header.Set("Content-Disposition", "inline;\n \tfilename=\""+encodeHeader(escapeQuotes(file.Name), msg.charset, 10)+`"`) - header.Set("Content-ID", "<"+msg.getCID(file.Name)+">") + if len(file.ContentID) > 0 { + header.Set("Content-ID", "<"+msg.getCID(file.ContentID)+">") + } else { + header.Set("Content-ID", "<"+msg.getCID(file.Name)+">") + } } else { header.Set("Content-Disposition", "attachment;\n \tfilename=\""+encodeHeader(escapeQuotes(file.Name), msg.charset, 10)+`"`) }