revMail on Win10, Outlook 2019 not working [SOLVED]

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

revMail on Win10, Outlook 2019 not working [SOLVED]

Post by stam » Mon Jun 19, 2023 12:10 pm

Hi all,

I have need of generating an email on a work machine, mainly because we don't have the direct emails of the addressees, only their names, which the exchange server finds the corresponding emails for - therefore much easier to just add addressees as <surname> <firstname> and have exchange send the email correctly.

RevMail works perfectly on my Mac - it constructs a message and addressees and subject from various fields. Because I have may work email in my mail.app, doing the above works famously - it identifies the email correctly and and can send.

The code is:

Code: Select all

revMail tAddress, tCCAddress, tMailSubject, tMessageBody
Full of joy, I thought I'd run this on Windows 10 (thank you NHS!!!) where my email client is Outlook, part of Office 2019, but no go. I just get the error message:
The command line argument is not valid. Verify the switch you are using.
Which is as clear as it is helpful.

This is slightly time critical - any help would be appreciated, and if all agree this is indeed a bug will create a bug report

Many thanks
Stam
Last edited by stam on Sat Jun 24, 2023 10:27 am, edited 1 time in total.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: revMail on Win10, Outlook 2019 not working

Post by stam » Mon Jun 19, 2023 1:01 pm

As an addendum:

1. revMailUnicode has the same issue (unsurprisingly).

2. If outlook is not running not the Windows machine, the error message changes slightly:
Cannot start Microsoft Outlook. The command line argument is not valid. Verify the switch you are using.

I fear very much this is not something I can address myself, and I can't see this as anything but a bug, so submitted a bug report here:
https://quality.livecode.com/show_bug.cgi?id=24240



Test stack attached - works perfectly on Mac, generates the errors above on Win10 / Outlook (MS Office 2019)

---- EDIT: WARNING: rename the stack to something that doesn't begin with rev; I foolishly didn't realise at the time that this is a no-no....
Attachments
RevMail fail with Outlook.livecode.zip
(1.78 KiB) Downloaded 70 times
Last edited by stam on Mon Jun 19, 2023 7:57 pm, edited 1 time in total.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: revMail on Win10, Outlook 2019 not working

Post by stam » Mon Jun 19, 2023 7:55 pm

As it doesn't look like a fix will be imminent, I spent hours trying to understand outlook 'switches' and tried my hand at using the command line on Windows. It almost works:

Code: Select all

command createEmailInClient pTo, pCC, pSubject, pBody
    local tCMD
    if the platform = "MacOS" then
        revMail pTo, pCC, pSubject, pBody
    else if the platform = "Win32" then
        if there is a file "C:\Program Files\Microsoft Office\root\Office16\Outlook.exe" then
            set the hideConsoleWindows to true
            put quote & "C:\Program Files\Microsoft Office\root\Office16\Outlook.exe" & quote into tCMD
            put " /c ipm.note" after tCMD
            put " /m " & quote & pTo & "?cc=" & pCC & "&subject=" & pSubject & "&body=" & pBody & quote after tCMD
            get shell(tCMD)
        else // try revMail anyway
            revMail pTo, pCC, pSubject, pBody
        end if
    end if
end createEmailInClient
This does make the assumption that the Outlook.exe is at C:\Program Files\Microsoft Office\root\Office16\Outlook.exe, if testing this may need adjusting.

The problem is that new lines inside pBody seem terminate the script - only the first line of text is displayed but there should be multiple lines...

Any ideas on how to pass a body text with multiple new lines guys? Can one use html with the cmd line?

Many thanks
Stam

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: revMail on Win10, Outlook 2019 not working

Post by SparkOut » Mon Jun 19, 2023 8:44 pm

Try replacing cr with "\n" in tBody, it might work - certainly SMTP servers will end the message on encountering an unescaped carriage return.
\n is not necessarily the way to escape a return in shell on Windows 10 though, I'll try and check (probably tomorrow) when I can use a computer.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: revMail on Win10, Outlook 2019 not working

Post by stam » Mon Jun 19, 2023 8:47 pm

SparkOut wrote:
Mon Jun 19, 2023 8:44 pm
Try replacing cr with "\n" in tBody, it might work - certainly SMTP servers will end the message on encountering an unescaped carriage return.
\n is not necessarily the way to escape a return in shell on Windows 10 though, I'll try and check (probably tomorrow) when I can use a computer.
Thanks @SparkOut, but that was one of the first things I tried... no dice. I found an obscure reference to replacing line-endings with %0D%0A instead (DOS-specific), this finally did the trick.

Final workaround:

stack script:

Code: Select all

command createEmailInClient pTo, pCC, pSubject, pBody
    local tCMD
    if the platform = "MacOS" then
        revMail pTo, pCC, pSubject, pBody
    else if the platform = "Win32" then
        if there is a file "C:\Program Files\Microsoft Office\root\Office16\Outlook.exe" then
            set the hideConsoleWindows to true
            put quote & "C:\Program Files\Microsoft Office\root\Office16\Outlook.exe" & quote into tCMD
            put " /c ipm.note" after tCMD
            put " /m " & quote & pTo & "?cc=" & pCC & "&subject=" & pSubject & "&body=" & replaceText(pBody, "\R", "%0D%0A") & quote after tCMD
            get shell(tCMD)
        else // try revMail anyway
            revMail pTo, pCC, pSubject, pBody
        end if
    end if
end createEmailInClient

Test stack attached - for me works on both Windows and MacOS. It's bit shaky because the path to MS Outlook is hard-coded and probably not the same with the various versions of Outlook (having said that, revMail probably works with older versions anyway!) - this gets me out of trouble until LC can fix this, but it's taken many hours I didn't have :-/
Attachments
createMailInClient.livecode.zip
(1.7 KiB) Downloaded 66 times

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: revMail on Win10, Outlook 2019 not working

Post by stam » Tue Jun 20, 2023 10:47 am

In way of update - this is a confirmed bug and has been marked as duplicate of a bug from 2018. I can't see another fix for this, but using the info in the duplicate bug report, I've removed the need for hard-coding the path to the email client (I know next to nothing about the Registry, so that bit of info was hand - actually googling for this led nowhere...) and shortened the handler.

This works just as well for my purposes, hopefully this will help others too:

Code: Select all

command createEmailInClient pTo, pCC, pSubject, pBody
    local tCMD, tMailApp
    if the platform = "Win32" then
        put word 1 of queryRegistry("HKEY_CLASSES_ROOT\mailto\shell\open\command\") into tMailApp
        put tMailApp & " /c ipm.note" & " /m " & quote & pTo & "?cc=" & pCC & "&subject=" & pSubject & \
              "&body=" & replaceText(pBody, "\R", "%0D%0A") & quote into tCMD
        get shell(tCMD)
    else
        revMail pTo, pCC, pSubject, pBody
    end if
end createEmailInClient

Again, this isn't a way to *send* email, it's a way to create a prepopulated email message for the user to send, which was my requirement.
Anyway hope this helps others until LC sort this issue out (given it's a 5 year old bug, it probably won't be fixed soon...)

S.
Last edited by stam on Sat Jun 24, 2023 10:28 am, edited 1 time in total.

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: revMail on Win10, Outlook 2019 not working [SOLVED]

Post by stam » Sat Jun 24, 2023 10:27 am

Hi all,
Just wanted to post an update with the solution in case others had a similar issue.

if you've been following the bug report above you'll see that this is a specific issue with revMail on Windows when using real names instead of emails (which is valid when using an Exchange server or similar).

Basically spaces in email fields lead to Outlook choking on the revMail code. Simply replacing spaces with %20 in the To: and CC: email fields resolves the issue completely - an email is generated in outlook and the exchange server recognises these appropriately and can email users (and no need to replace line endings in body text).

Interestingly using real names (with spaces) on MacOS connected to the same exchange server doesn't have this requirement, but if you do replace spaces with %20 in the email fields on MacOS it still works fine - so my code has now simplified greatly, as I no longer need to run this as a shell script on Windows...

Thanks to Matthias Rebbe, Panos Merakos and Mark Waddingham for helping identify this problem! Final app went live yesterday :)
Hopefully this will be added to the documentation so it's obvious...

Regards
Stam

Post Reply

Return to “Windows”