我在开发一个雷鸟插件,需要发送由插件而不是用户编写的邮件。
我尝试这样做,但不起作用:
var am = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
var cf = Components.classes["@mozilla.org/messengercompose/composefields;1"].createInstance(Components.interfaces.nsIMsgCompFields);
cf.from = "somebody@somewhere.com";
cf.to = "somebodyelse@somewhere.com";
cf.subject = "test";
cf.body = "just a testrn";
var params = Components.classes["@mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams);
params.composeFields = cf;
var msgSend = Components.classes["@mozilla.org/messengercompose/send;1"].createInstance(Components.interfaces.nsIMsgSend);
var msgCompose = Components.classes["@mozilla.org/messengercompose/compose;1"].createInstance(Components.interfaces.nsIMsgCompose);
msgCompose.compFields = cf;
msgCompose.initialize(window,params); //[Exception... "Could not convert JavaScript argument arg 0 [nsIMsgCompose.initialize]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: *****" data: no]
msgCompose.SendMsg(msgSend.nsMsgDeliverNow, am.defaultAccount.defaultIdentity, am.defaultAccount.key, null, null);
任何人都知道我的错误在哪里或一个简单的方法可以做到这一点?
谢谢
从插件发送电子邮件是一项令人难以忘怀的复杂任务。幸运的是,库存在,即以 thunderbird-stdlib 的形式存在。有关 sendMessage
函数的实现,请参阅 https://github.com/protz/thunderbird-stdlib/blob/master/send.js#L228,有关如何使用该函数的示例,https://github.com/protz/GMail-Conversation-View/blob/master/content/stub.compose-ui.js#L879 请参阅。