Send a mail automatically in an thunderbird addon - email

I work on a thunderbird addon and a need to send a mail written in by the addon and not by the user.
I try to do this with that but is doesn't work :
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 test\r\n";
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);
Anyone know where is my mistake or a simple method to do that ?
Thanks

Sending an email from an addon is a hauntingly complex task. Fortunately, libraries exist, namely in the form of thunderbird-stdlib. See https://github.com/protz/thunderbird-stdlib/blob/master/send.js#L228 for the implementation of the sendMessage function, https://github.com/protz/GMail-Conversation-View/blob/master/content/stub.compose-ui.js#L879 for an example of how to use the function.

Related

MailKit HtmlBody Always Null

I"m trying to get the html from an email retrieved in Gmail. No issues getting the emails however when I attempt to get the HtmlBody it is always null. HTML is present according to the bodyparts.
using (var imap = new ImapClient())
{
imap.Connect("imap.gmail.com", 993);
imap.Authenticate(Login, PW);
var inbox = imap.Inbox;
inbox.Open(FolderAccess.ReadWrite);
string body = "";
if (html)
{
body = inbox.GetMessage(messageID).HtmlBody;
} else
{
body = inbox.GetMessage(messageID).TextBody;
}
imap.Disconnect(true);
return body;
}
I can see from the bodyparts that html is present and if I use this linq I'm able to get the encoded html.
var msg = inbox.GetMessage(messageID).BodyParts.OfType<MimePart>().First(x => x.ContentType.MimeType == "text/html");
Using this I can see there is a Text property but I'm not able to retrieve it. Can anyone assist in getting the unmodified html from Mailkit?
If you change your LINQ statement to:
var msg = inbox.GetMessage(messageID).BodyParts.OfType<TextPart>().First(x => x.ContentType.MimeType == "text/html");
... you'll be able to access the .Text property.
The other option is to cast the msg variable to a TextPart.
The reason you can't access the .Text property in your current code is that this property only exists on the TextPart subclass of MimePart (which is more abstract).

The combination of parameters is either not valid or not complete. Parameter name: importRequest

I am trying to create a GitImportRequest with the Microsoft.TeamFoundation.SourceControl.WebApi library, but I keep getting this error message:
{"The combination of parameters is either not valid or not complete.\r\nParameter name: importRequest"}
This is what my code to create the GitImportRequest looks like.
var gitSrc = new GitImportGitSource();
gitSrc.Url = gitUrl;
gitSrc.Overwrite = true;
var gitImportParams = new GitImportRequestParameters();
gitImportParams.GitSource = gitSrc;
var gitImportRequest = new GitImportRequest();
gitImportRequest.Repository = targetRepository;
gitImportRequest.Parameters = gitImportParams;
What am I missing? I have looked at the Azure Devops Api Import page with no success.
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/import-requests/create?view=azure-devops-rest-6.0

How to run a dll from Thunderbird and get a return value

I have a dll and I'd like to run it from Thunderbird and get a return value.
Is there an extension that already does it?
Thanks
Alb
You can do this using js-ctypes. Here is an example from MDN:
Components.utils.import("resource://gre/modules/ctypes.jsm");
var lib = ctypes.open("C:\\WINDOWS\\system32\\user32.dll");
/* Declare the signature of the function we are going to call */
var msgBox = lib.declare("MessageBoxW",
ctypes.winapi_abi,
ctypes.int32_t,
ctypes.int32_t,
ctypes.jschar.ptr,
ctypes.jschar.ptr,
ctypes.int32_t);
var MB_OK = 0;
var ret = msgBox(0, "Hello world", "title", MB_OK);
lib.close();
See https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes for more details and examples.

Reading mail from open source Mirthconnect

I'm facing an issue with Mirthconnect.
I just have a trouble in this process. I like to read the data from mail, is it possible to acheive this in the open source mirthconnect? of version 3.3.1, if so is it possible to read from direct mail?. Apart from the commerical versions like mirth mails.
I made use of JAVA mail library and inserted it in the custom library folder of mirth connect then used the following code in the connector portion of mirth. It works well.
//Fetchmail from Gmail
var props = new Packages.java.util.Properties();
props.setProperty("mail.store.protocol", "imaps");
var session = new Packages.javax.mail.Session.getInstance(props, null);
var store = session.getStore();
store.connect("imap.gmail.com", "xxxxxxxx#gmail.com", "xxxxxxxxx");
var inbox = store.getFolder("INBOX");
inbox.open(Packages.javax.mail.Folder.READ_ONLY);
var msgs = inbox.getMessage(inbox.getMessageCount());
var currentMessage = inbox.getMessage(inbox.getMessageCount());
var mp = currentMessage.getContent();
var bp = mp.getBodyPart(0);
var content = "" + bp.getContent();
content = content.replace(/''/g, "");
globalMap.put('gcon', content);
logger.info("SENT DATE:" + msgs.getSentDate());
logger.info("SUBJECT:" + msgs.getSubject());
logger.info("CONTENT:" + content);
//bp.getContent()
var receiveId = UUIDGenerator.getUUID();
logger.info("incomingMailID : "+receiveId);
//Database Connectivity
var time= msgs.getSentDate();
var con = bp.getContent();
var sub = msgs.getSubject();
//global variable declaration
globalMap.put('glcontent',con);
globalMap.put('glsubject',sub);
globalMap.put('gltime',time);
return sub;
Then you can set the the polling frequency time intervalin the listener which the mirth channel will poll for that specific time interval.

Script to name form response spreadsheet based on form title in Google Drive

I need a script to be able to create the form response spreadsheet of a Google Form and name that Spreadsheet the same as the Form + (Responses) at the end of the name. I have no idea how to do this. I am guessing it has to do with the script below, but the script does not understand that "Title" is the same as a "Name". (I do not know how to append the "(Responses)" part at the end either.) Any help would be appreciated.
function myFunction() {
var form = FormApp.openById('FORM ID HERE').getTitle();
var ss = SpreadsheetApp.create(form);
form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
}
I found the answer and also how to apply it to many forms in a folder. The answer is below.
function myFunction() {
var files = DriveApp.getFolderById("0B6Eeub3cEBoobnpxWXdjSWxJRm8").getFiles()
while (files.hasNext()) {
var file = files.next();
var form = FormApp.openById(file.getId());
var formName = DriveApp.getFileById(file.getId()).getName();
var ss = SpreadsheetApp.create(formName + ' (Responses)');
form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
}
}