Email Attachments on Windows

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
KimD
Posts: 184
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Email Attachments on Windows

Post by KimD » Thu Feb 07, 2019 3:24 am

Hi

I'm hoping to get some advice on which Livecode email solution to use within an app which I'm developing.

Requirements:
- must work on Windows desktop, Android & IOS mobile; but - if that's what's required - I am happy to use MobileComposeMail for Android & IOS, and something else for Windows desktop. It is the windows desktop solution that I'm stuck on at the moment
- within my LC app, I want the user to be able to select a file generated by the app, then have the email client open with that file pre-loaded as an attachment.
- Ideally, I'd like the users default email client to be the one which opens with the attachment pre-loaded.

At the moment my thinking is that the way to go is:
- Mobile - MobileComposeMail; plus
- Windows - HMTL mail, but my understanding is that this would mean dropping "I'd like the users default email client to be the one which opens". I'm heading down this path because my understanding is that a RevMail solution couldn't handle attachments and a TsNet mail solution would require me to store the attachment on an external server (which I don't want to have to do).

Is there a better way of doing this?

Thanks in advance

Kim

AndyP
Posts: 447
Joined: Wed Aug 27, 2008 12:57 pm
Location: Seeheim, Germany (ex UK)
Contact:

Re: Email Attachments on Windows

Post by AndyP » Thu Feb 07, 2019 6:59 am

Have a look at these registry items.

HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail

HKEY_CURRENT_USER\Software\Clients\Mail

And an interesting thread on getting registry values here


http://runtime-revolution.278305.n4.nab ... 83142.html
Andy Piddock

http://2108.co.uk/tinyide/ - Mini LC IDE alternative

http://2108.co.uk/script-editor-themer/ - Script Editor colour theming

http://livecodeshare.runrev.com/stack/897/LiveCode-Multi-Search - Search across 8 LC resources

AxWald
Posts: 362
Joined: Thu Mar 06, 2014 2:57 pm

Re: Email Attachments on Windows

Post by AxWald » Thu Feb 07, 2019 12:21 pm

Hi,
KimD wrote:
Thu Feb 07, 2019 3:24 am
Is there a better way of doing this?
I don't know if this meets your preferences, but I'm using MailAlert for all of my email business on Windows. It's a tiny command line program that just sends mails as commanded - but with a very powerful feature set. I have yet to find an email problem that MailAlert cannot defeat ;-)

Have fun!
Livecode programming until the cat hits the fan ...

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6791
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Email Attachments on Windows

Post by FourthWorld » Thu Feb 07, 2019 5:33 pm

I had thought the mailto URL scheme supports an attachment option, no? If it does, URL schemes can be triggered in LC with the launch URL command.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Klaus
Posts: 11113
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Email Attachments on Windows

Post by Klaus » Thu Feb 07, 2019 5:42 pm

Hi Richard,

unfortunately the "mailto:" protocoll does NOT support attachments.
That was my first thought, too. :D


Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6791
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Email Attachments on Windows

Post by FourthWorld » Thu Feb 07, 2019 6:32 pm

It seems PowerShell provides a handler for that URL scheme, which could be triggered from within LC with the shell function:

https://forums.asp.net/t/1287236.aspx?O ... attachment
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

KimD
Posts: 184
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Re: Email Attachments on Windows

Post by KimD » Fri Feb 08, 2019 4:19 am

Thanks all

I will follow-up on the Powershell option. I've never worked with calling another programme from LC before. My understanding of what I will need to do is:
1) Use a tool like PS2EXE-GUI to create a PowerShell standalone executable, that accepts arguments (e.g. email attachment file name)
2) Include the PowerShell standalone executable in the LC Standalone App Settings > Copy Files
3) Use the registry entries mentioned by AndyP to test whether there is an email client on the PC
4) If there is an email client - use the following LC script to execute the PowerShell standalone executable -
get shell(powershell_standalone_executable_name argument_list)

Is that the general idea?

I did a test run with writing a "hello world" type VBS standalone executable (which accepted an argument) and triggering that using get shell(). That worked fine.

My understanding is also that my LC standalone will lock-up until after the powershell_standalone_executable has completed its task (sending an email) and returned a result to LC. Is that correct?

Currently being hit by alternating waves of fear about implementing email attachments on Windows and waves of appreciation for MobileComposeMail ;-)

Kim

sphere
Posts: 900
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Email Attachments on Windows

Post by sphere » Fri Feb 08, 2019 8:24 am

You could use Sarah Reichelts SMTP library, it's excellent for this. Then you don't need the email client of the customer. You can add text and any attachment you want. And email from within your application.
2018 Worldwide Mobile Market share: Android 84.4% !!!, iOs 15.1%, others 0.1%

AxWald
Posts: 362
Joined: Thu Mar 06, 2014 2:57 pm

Re: Email Attachments on Windows

Post by AxWald » Fri Feb 08, 2019 10:26 am

Hi,
sphere wrote:
Fri Feb 08, 2019 8:24 am
You could use Sarah Reichelts SMTP library, it's excellent for this.
I was under the impression that it wouldn't work anymore with more "modern" email servers that require SSL and/or STARTTLS (gmail etc.).
sphere wrote:
Fri Feb 08, 2019 8:24 am
Then you don't need the email client of the customer.
That's why I'd never even try the above mentioned (Powershell/ mailto:) solution: There's a lot of different mail clients out there, among these may well be some that don't support the mailto: protocol sufficiently. Problem!
Then there's a lot of ppl that don't use any mail client at all, but use a web front end via browser. Problem, again!
Then, there's ppl out there that are reluctant to use their email account other than for well known friends, fearing you'd sell their address to 'em spammers. Problem, again!

@OP:
KimD wrote:
Fri Feb 08, 2019 4:19 am
I've never worked with calling another programme from LC before.
Then:
KimD wrote:
Fri Feb 08, 2019 4:19 am
I did a test run with writing a "hello world" type VBS standalone executable (which accepted an argument) and triggering that using get shell().
??? Isn't this a contradiction?

Besides, I cannot but feel you're shooting yourself in the foot, through the eye:
  1. You use a tool to create a PowerShell standalone executable that accepts arguments.
  2. You add this executable to your program.
  3. You read the registry to find out if there's an email client.
  4. If not, you've lost.
  5. If yes, you call it via "get shell(powershell_standalone_executable_name argument_list)"
Why not:
  1. You add the MailAlert folder (2MB) to your program.
  2. You call it via "get shell(pathTo/MailAlert.exe argument_list)"
Bonus: You can even provide a default sender account if the user doesn't have an email account, or is not willing to use its own. This is most useful if you use it to send error alerts to yourself in case your program ends up with a critical mistake ...

Then, besides this there's web services you can connect to via http to send mail. A lot of possibilities. Choose what suits you best!

Have fun!
Livecode programming until the cat hits the fan ...

KimD
Posts: 184
Joined: Wed Jul 08, 2015 5:51 am
Location: Wellington, New Zealand

Re: Email Attachments on Windows

Post by KimD » Sun Feb 10, 2019 12:18 am

Hi AxWald

True - I'll revise my statement - Other than a "Hello World" VB script which I wrote as a test after reading the above responses to my original post, I've never worked with calling another programme from LC.

The thing that put me off MailAlert was that it seemed to me that this solution would require users of my app to input parameters (username, password, etc) to setup MailAlert to work with their existing email client/account. If it was just me that would be using the app then I would do this. But I think that its unlikely that my intended user-base will be willing to jump through this extra hoop. I hadn't thought of setting up a default email account on MailAlert. That would mean that the emails originating from my app came from a default email address and not the users email address. Again, that will put some potential users off, but I'll give this some more thought. The impression that I gained from reading the responses to my original post are that there is no easy/complete solution to my requirement, and that I need to choose between a range of non-ideal options. I guess that this is just an artifact of the wide-range of possible email solutions that users might be using on Windows. If it was easy, as easy as Android & IOS mobile, then I suspect that LC would already feature a WindowsComposeMail command.

Thanks for taking the time to offer your advice though. It is appreciated.

Kim

AxWald
Posts: 362
Joined: Thu Mar 06, 2014 2:57 pm

Re: Email Attachments on Windows

Post by AxWald » Sun Feb 10, 2019 1:58 pm

Hi KimD,

I admit the sheer numbers of possibilities (that MailAlert offers) can be irritating. But actually it's quite simple - it uses an .ini file for the configuration:

Code: Select all

[CONFIGURATION]
To=monitor@example.org
From=automail@example.org
ReplyTo=info@example.org
;Cc=admin2@example.org,admin3@example.org
;Bcc=info@example.org
FullName=Example.org Mail Bot
SMTPServer=mailIn.example.org
SMTPPort=587
EnableAutoTLS=yes
EnableSMTPS=no
Username=aUserName
[Password=123456] only for 1st run, will be replaced with EncryptedPassword
Importance=Normal
PlaintextOnly=no
VerboseMode=no
Charset=ISO-8859-1
EncryptedPassword=tsk4doPSB0/EmUl8jc73p4g7465IYmx/
Here you enter the basic parameters that are used when sending mail. Some of these (mainly recipient data) you'll overwrite later (during sending).
Since this is a simple text file & read each time MailAlert is invoked it's quite easy to juggle different versions of it, as you need it.

I have the sender data in a database & create a valid .ini for the current user at program startUp, but also can switch it on demand (so the user can send mails using its account, and I can send me alarms using a generic alarm account).
The "Password=" is only needed for the first run, MailAlert will encrypt it & use "EncryptedPassword=" then. More of this further down.

Invoking MailAlert is quite easy then:

Code: Select all

function sendMyMail what
   get the cHPat of this stack  --  the applications home directory => The:/Path/to/
   replace slash with backslash in it
   put quote & it & gMailExeName & quote into myShell  --  => "The:\Path\to\MailAlert.exe"
   if gMailUrgency is empty then put "Low" into gMailUrgency  --  default urgency
   
   put " -r " & quote & gMailTo & quote after myShell  --  To:
   put " -c " & quote & gMailCC & quote after myShell  --  CC:
   put " -u " & quote & gMailBCC & quote after myShell  --  BCC:
   put " -s " & quote & gMailSubject & quote after myShell  --  Subject:
   put " -b " & quote & what & CR & CR & quote after myShell  --  Bodytext:
   put " -d -i " & quote & gMailUrgency & quote after myShell  --  DateTime, Urgency
   
   set the hideConsoleWindows to true
   return shell(myShell)
end sendMyMail
I use a custom property here, and quite some global variables. This could be local variables, an array, whatever.
This function should return 0, else an error occurred.

About the encrypted password:
This adds a bit of complexity: Basically, when the user enters its account data, you create an .ini with the "password=" entry & no "EncryptedPassword=", with any known good recipient address. Then you call "MailAlert.exe -t", this will send a test email using the data in the .ini & encrypt the password in this file.
Then you check the result - it should be 0 for a successful send. If you get this, you tell the user that the setup succeeded, you forget the password that was entered & instead save the encrypted version, for further use.

Still confusing?
Guess it's unavoidable for a tool with that many possibilities. And I may have deficiencies explaining such ;-)
Maybe it helps if I show my use cases:
  • It's used in my programs to enable the user to send whatever mails to whomever, using whose ever email account (this is usually restricted as the customer specifies, but often used for registering at business-related forums, mailing lists etc.).
  • It's used in my programs to enable the user to send formalized offers/ orders/ acknowledgements to the customers/ suppliers, using the appropriate business account.
  • It's used in unattended parts of my programs (standalone daemons) to auto-send orders & acknowledgements, using a mail bot account.
  • And last but not least, I use it to report critical errors to me, both in user driven & unattended parts of my programs, using my own prioritized alarm account that makes all of my gadgets explode in bells & whistles.
This it does for years now, for millions of mails, without a single problem yet.
This may be a reason I cannot help but feel myself sounding a bit like an evangelist now :)

Have fun!
Livecode programming until the cat hits the fan ...

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”