Page 1 of 1

Opening native mail application with content

PostPosted: Wed Apr 10, 2024 6:32 pm
by alasdairs
Hi all,

I need the ability to open a new email on a clients computer that has information plugged into it, including an attachment, text, who its from, and subject. The only way I can think of doing it is using executeProgram('open /path/to/information -a mail.app), but I'm not sure how to get it to open on the clients computer, with all of that information. Is there a way to write a file which will open mail with all of that information (for example a JSON file), and is there a way for it to execute on the clinets machine instead of the server?

I think they all use mac, so I won't need to write it for different programs.

Thanks,
Alasdair

Re: Opening native mail application with content

PostPosted: Wed Apr 10, 2024 11:46 pm
by robert.edelmann
Mails generally can be saved in different file formats, but almost all programs can open files in the eml-format, which is described here https://en.wikipedia.org/wiki/Email#Filename_extensions.

It's basically the raw email as it was sent over the network.

I'm not sure what emails you want to open, are these mails that have been received via the internet or do you want to create new emails to be sent by the user?

In the first case you could save the raw data into a field and just save that into in a file on the users machine and open the file if you are on ngdesktop

Code: Select all
    if (application.getApplicationType() == APPLICATION_TYPES.NG_CLIENT && plugins.ngdesktoputils.isNGDesktop()) {
[...]
      plugins.ngdesktopfile.writeFile(targetFileName, bytes);
      if (targetFileName) {
         plugins.ngdesktopfile.openFile(targetFileName);
      }
   } else {
      if (mimeType) {
         success = plugins.file.writeFile(dateiName, bytes, mimeType);
      } else {
         success = plugins.file.writeFile(dateiName, bytes);
      }
[...]
   }


If you want to prepare a mail to be sent, I'm not sure if you can just create a file to be sent. We create a new message in the draft-folder of the users mail-account to do that, and the user can then take over in his mailclient of choice.

We use the mailpro-plugin from http://www.servoy-plugins.de/ to handle the imap-stuff, if you want to go the Office365-route and use graph you can also save drafts that the user can send then.

And yes all this works on mac and on windows.

Re: Opening native mail application with content

PostPosted: Thu Apr 11, 2024 8:16 am
by mboegem
Hi Alasdair,

Robert already gave you some pointers of how to achieve what you want.

The standard way in javascript to open a new mail and prefill fields is this:
Code: Select all
function sendEmail() {
  var to = "recipient@example.com";
  var subject = "Hello!";
  var body = "Just wanted to say hi.";

  var mailtoLink = "mailto:" + to +
                   "?subject=" + encodeURIComponent(subject) +
                   "&body=" + encodeURIComponent(body);

  application.showURL(mailtoLink);
}


But the options are limited and attachments can not be prefilled this way.

You also mentioned the 'from' field.
This is not really a choice for a lot of providers nowadays.
To avoid abuse they force you to make the 'from' email address match the account of the mailbox.

Last but not least: you mentioned the 'executeProgram' command.
Be aware that for (Ti)NG this is only available using the NGDesktop client.

Hope this helps making the choice.

Re: Opening native mail application with content

PostPosted: Mon Apr 15, 2024 4:02 pm
by alasdairs
Hi Robert and Marc,

I wanted to be able to create a .eml file which was seen as a draft from macos but didn't realise how hard that would be to implement. I'm thinking I'm just going to create a simple 'email' form in the solution and have the server send mail with the mail plugin.

Talking about the executeProgram function, I have used the function elsewhere in my solution and have it currently hosted on a server, which I connect to through the browser on my computer and it seems to work just fine, executing the commands I have implemented. Should it not be working? It tells me it's deprecated, but it still seems to have all the functionality I need it to have currently.

Thanks,
Alasdair

Re: Opening native mail application with content

PostPosted: Mon Apr 15, 2024 4:14 pm
by mboegem
Hi Alasdair,

Email form sounds like the easiest way indeed.

Concerning executeProgram, in 2024.3 it doesn't show as deprecated, but maybe it has to do with the parameters.
executeProgram will work, however this will be a serverside action.

Hope this helps