Changing who the email is from with WIN32OLE

1

Is there a way to change who an email is from using win32ole?

outlook = WIN32OLE.new('Outlook.Application')
message = outlook.CreateItem(0)
message.Subject = 'Test email'
message.Body = 'This is the test body'
message.To = 'test@test.test'
message.From = ''me@me.me' #<= This doesn't work
message.Save
message.Send

When you run message.From you get the following error:

WIN32OLERuntimeError: unknown property or method: `From'
    HRESULT error code:0x80020006
      Unknown name.

So is there a way I can choose who the message is sent from?

ruby
email
outlook
win32ole

1 Answer

1

When sending through Exchange, use SentOnBehalfOfName property. It should contain the name of another Exchange user on who's behalf the current user can send. You of course need to have the right to send on behalf of that user.

When sending through SMTP, set the MailItem.SendUsingAccount property instead. It must be set to one of the Account objects retrieved from the Namespace.Accounts collection.


User contributions licensed under CC BY-SA 3.0