I’m trying to create extension for Thunderbird, that will create and
send e-mail with html content and embedded image (through ). Many things
work fine, however I don’t know how to add neccessary Content-ID header
for image attachment.
Here is my code to send e-mail based on my custom maildef object
describing e-mail. It creates attachments according to
maildef.attachments array, but it does not give them Content-ID, because
I don’t know how.
SendMessage: function(maildef, identity) {
var composeService = Components.classes["@mozilla.org/messengercompose;1"].getService(Components.interfaces.nsIMsgComposeService);
if (!identity)
identity = composeService.defaultIdentity;
var composeFields = Components.classes["@mozilla.org/messengercompose/composefields;1"].createInstance(Components.interfaces.nsIMsgCompFields);
composeFields.to = maildef.to;
composeFields.from = identity.identityName;
composeFields.body = maildef.body;
composeFields.subject = maildef.subject;
//composeFields.characterSet = 'UTF-8';
if (maildef.html) {
composeFields.forcePlainText = false;
composeFields.useMultipartAlternative = false;
}
else {
composeFields.forcePlainText = true;
composeFields.useMultipartAlternative = false;
}
if (maildef.attachments) {
for(var i = 0; i < maildef.attachments.length; i++) {
var attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"].createInstance(Components.interfaces.nsIMsgAttachment);
attachment.contentType = maildef.attachments[i].mime;
attachment.url = 'file://' + maildef.attachments[i].path;
attachment.name = maildef.attachments[i].name;
attachment.temporary = false;
composeFields.addAttachment(attachment);
}
}
var MsgComposeParams = Components.classes["@mozilla.org/messengercompose/composeparams;1"]
.createInstance(Components.interfaces.nsIMsgComposeParams);
MsgComposeParams.composeFields = composeFields;
if (maildef.html)
MsgComposeParams.format = 1;
else
MsgComposeParams.format = 2;
var msgCompose = Components.classes["@mozilla.org/messengercompose/compose;1"].createInstance(Components.interfaces.nsIMsgCompose);
msgCompose.initialize(MsgComposeParams);
msgCompose.SendMsg(1, identity, identity.key ,null,null);
}