Hi all,
For sending emails from my Clarion app I use an OLE control with a piece of VB script. This works fine, but the default (MS Outlook) signature in the body is missing. I read on stack overflow that this will be placed in the body. But not tin my case. I may be missing perhaps one line of code to fill the body with the preferred signature from Outlook.
Does anyone have a suggestion?
VB script:
?OleOutlook{‘Application.Visible’} = True
?OleOutlook{PROP:Create}=‘outlook.application’
OutMail=?OleOutlook{‘createItem(0)’}
IF OutMail[1]<>‘`’
MESSAGE(‘Cannot send a message by Microsoft Outlook.’,‘Error’,ICON:Hand)
ELSE
?OleOutlook{OutMail&‘.Subject’} = ‘Your invoice 123456’
?OleOutlook{OutMail&‘.To’} = ‘[email protected]’
?OleOutlook{OutMail&‘.HTMLbody’} = ???
?OleOutlook{OutMail&‘.Attachments.Add(’&Invoice123456.PDF&‘)’}
?OleOutlook{OutMail&‘.Display’}
END
?OleOutlook{‘Application.Display’} = True
?OleOutlook{‘Application.Visible’} = True
Regards,
Henk Ouwejan
Hi Henk,
I asked ChatGPT, and it suggested that the issue might be due to how the Outlook Object Model handles signatures. When setting the HTMLBody
or Body
property, Outlook replaces the entire email content, including the signature. Obviously GPT has also been known to be wrong.
Below is the adjusted code incorporating the suggestion to include the signature by appending custom content to the existing body:
?OleOutlook{'Application.Visible'} = True
?OleOutlook{PROP:Create} = 'outlook.application'
OutMail = ?OleOutlook{'createItem(0)'}
IF OutMail[1] <> '`'
MESSAGE('Cannot send a message by Microsoft Outlook.', 'Error', ICON:Hand)
ELSE
ExistingBody = ?OleOutlook{OutMail & '.HTMLBody'} ! Retrieve the existing content, which includes the signature
IF LEN(ExistingBody) = 0
MESSAGE('Default signature not found.', 'Warning', ICON:Exclamation)
END
NewContent = '<p>Your invoice 123456</p>' ! Add your custom content here
?OleOutlook{OutMail & '.Subject'} = 'Your invoice 123456'
?OleOutlook{OutMail & '.To'} = '[email protected]'
?OleOutlook{OutMail & '.HTMLBody'} = NewContent & ExistingBody ! Append your content to the signature
?OleOutlook{OutMail & '.Attachments.Add(' & Invoice123456.PDF & ')'}
?OleOutlook{OutMail & '.Display'}
END
?OleOutlook{'Application.Display'} = True
?OleOutlook{'Application.Visible'} = True
Tip for Posting Code on the Forum:
When posting clarion code on the forum, you can format it for better readability by wrapping it with three backticks ``` followed by the word clarion
at the start and three backticks at the end. For example:
```clarion
! Your Clarion code here
``` becomes.
! Your Clarion code here
Mark
Hello Mark,
Thank you for the tip for displaying readable Clarion code (much better )
The HTMLBody was still empty. The third ChatGPT solution I got (ChatGTP is my new friend) this:
! Add signature (Outlook will do this for you)
?OleOutlook{OutMail&'.Display'}
This code must before: ExistingBody =
And now it works