Jump to content

Set Sender Address in Outlook


rosaz
 Share

Recommended Posts

Hello, I have automated creating an Outlook message and need to add in to specify the Sender's address. However I can't figure out how to reference that field. Here's what I have so far:

Local $olMailItem = 0
$oOApp = ObjCreate("Outlook.Application")
$oOMail = $oOApp.CreateItem($olMailItem)
With $oOMail
    .To = "email recipient"
    .Subject = "subject
    .Body = "Hello"
.Display
EndWith

Any help is very much appreciated! Thank you!!

Link to comment
Share on other sites

Try "$oOMail.From" ?

I don't have outlook installed on this computer, but if i remember correctly, the From property is read only... in addition to that it looks like you're assigning literal strings where you probably want variables, and you've got the string for the subject line unterminated...
Link to comment
Share on other sites

I don't have outlook installed on this computer, but if i remember correctly, the From property is read only...

Yah you may be right...my Outlook is on Exchange and only one mailbox but in a multi-mailbox setup you can change who the mail sender is. But again, even though it can be changed manually, doesn't mean you'll be able to change it using the Object in a script... I'll install Outlook at home and add two regular mailboxes and see if I can change the sender via script, though I'm sure it's been covered in this forum somewhere already...

Link to comment
Share on other sites

Yah you may be right...my Outlook is on Exchange and only one mailbox but in a multi-mailbox setup you can change who the mail sender is. But again, even though it can be changed manually, doesn't mean you'll be able to change it using the Object in a script... I'll install Outlook at home and add two regular mailboxes and see if I can change the sender via script, though I'm sure it's been covered in this forum somewhere already...

in outlook, just press alt+f11 to go into the vba environment, then F2 i believe loads the object viewer. go down and check the properties of mailitem to see the from field.
Link to comment
Share on other sites

in outlook, just press alt+f11 to go into the vba environment, then F2 i believe loads the object viewer. go down and check the properties of mailitem to see the from field.

ok olMailItem has "SenderEmailAddress" and "SenderName" properties but they are read-only.

There is also a "SentOnBehalfOfName" and it's not read-only so it should be able to be set, right? Not sure how useful it will be in a non-exchange environment though...

Link to comment
Share on other sites

ok olMailItem has "SenderEmailAddress" and "SenderName" properties but they are read-only.

There is also a "SentOnBehalfOfName" and it's not read-only so it should be able to be set, right? Not sure how useful it will be in a non-exchange environment though...

in order to be able to actually send from a different address with that field, a delegate has to be setup by that account on the exchange server.
Link to comment
Share on other sites

in order to be able to actually send from a different address with that field, a delegate has to be setup by that account on the exchange server.

Yea and it will still arive as "Sent on behalf of Sender" but not as actually sent FROM Sender.

So Rosaz, I think the answer would be NO, can't change sender address using script. Guess you can try to change it via mouse and keyboard control though...

Link to comment
Share on other sites

Yea and it will still arive as "Sent on behalf of Sender" but not as actually sent FROM Sender.

So Rosaz, I think the answer would be NO, can't change sender address using script. Guess you can try to change it via mouse and keyboard control though...

as long as the account is setup in accounts in outlook, i'm confident that there is a way to do it, but i don't have outlook here to get into the object model to spell it out. go into the object browser and follow the objects down from Application until you find the correct property to set. OR the VBA help file has a fair amount of examples for just about anything, do a search there for creating a new mail item, and it may have the property mentioned in the WITH statement. Or i think you can even start recording a macro, create a new mail message, and then change your from property, then examine the generated macro to get it.
Link to comment
Share on other sites

Or i think you can even start recording a macro, create a new mail message, and then change your from property, then examine the generated macro to get it.

This would make it easier, but I don't think Outlook lets you record macros, unless I'm missing something there too. If you figure out how, please let me know! That would be nice to be able to do...

Link to comment
Share on other sites

This would make it easier, but I don't think Outlook lets you record macros, unless I'm missing something there too. If you figure out how, please let me know! That would be nice to be able to do...

it would be under tools>macros>record macro if the functionality is there
Link to comment
Share on other sites

this works for me:

With $oOMail
        .To = ($to)
        .SentOnBehalfOfName = ("mail@yahoo.com")
        .Display
    EndWith

"mail@yahoo.com" is a mailbox i have added in outlook and i have full rights on it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...