Opening native mail application with content

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Opening native mail application with content

Postby alasdairs » Wed Apr 10, 2024 6:32 pm

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
Software Engineer
alasdairs
 
Posts: 46
Joined: Wed Dec 27, 2023 10:06 pm
Location: The Internet

Re: Opening native mail application with content

Postby robert.edelmann » Wed Apr 10, 2024 11:46 pm

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.
mit freundlichen Grüßen
Robert Stefan Edelmann
User avatar
robert.edelmann
 
Posts: 95
Joined: Wed Aug 14, 2013 6:12 pm

Re: Opening native mail application with content

Postby mboegem » Thu Apr 11, 2024 8:16 am

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.
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1752
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Opening native mail application with content

Postby alasdairs » Mon Apr 15, 2024 4:02 pm

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
Software Engineer
alasdairs
 
Posts: 46
Joined: Wed Dec 27, 2023 10:06 pm
Location: The Internet

Re: Opening native mail application with content

Postby mboegem » Mon Apr 15, 2024 4:14 pm

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
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1752
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests