Using VBA, the simplest way to get Outlook to add an email signature to
an email body is to use the mail “display” method.
However, because WIN32OLE uses method_missing to send commands, it seems
to be Object#display which is being triggered, simply displaying the
mail’s object ID in the console.
Is there a way for me to get around this behaviour and get the correct
WIN32OLE method called? I had considered undefining Object#display, but
that seems like a rather dangerous thing to do.
I remembered the word “singleton” and looked into it until I found a
workaround.
Here’s the solution (for posterity):
New mail
m = outlook.CreateItem(0)
Remove Object#display only for this instance
class << m
undef display
end
This now calls win32ole display correctly
m.display
Extract the signature
signature = m.htmlbody
Set the mail to use HTML
m.bodyformat = 2
Set a custom mail body with the default signature
m.htmlBody = body + signature
Hi,
2013/5/13 Joel P. [email protected]
that seems like a rather dangerous thing to do.
You can use WIN32OLE#invoke method like this:
excel = WIN32OLE.new(‘Excel.Application’)
excel.invoke(‘Quit’) # => same as excel.Quit
Regards,
Park H.
Thanks, that looks like a better option!