Thunderbird addon - send email with embedded image (content-id)

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);

}

Not too many thunderbird devs :frowning:

This forum has a couple guys - http://forums.mozillazine.org/viewforum.php?f=19

I chatted with someone I know involved in the Thunderbird project, this is what they told me:

Unfortunately not many people know that part of the code.

The IRC channel #maildev is a good place to ask and wait, hopefully someone can help. Although on a second look it may be too low level, maybe just ask in the channel on a weekday in the PST workday. From some quick checks it doesn’t seem like the msgComposeFields stuff allows directly manipulating the attachment content id. The addAttachment method may just be for real attachments.

This is a pretty magical area of Thunderbird. I remember back in the days we wanted to make sure that when sending invitation emails in Lighting using similar methods, we were not able to influence the order in which the attachments are sent, which breaks compatibility with Outlook if done wrong.

Here is a HTML5 IRC client to the #maildev channel - https://client00.chat.mibbit.com/?url=irc%3A%2F%2Firc.mozilla.org%2F%23maildev