Jump to content
Sign in to follow this  
rosaz

Set Sender Address in Outlook

Recommended Posts

rosaz

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!!

Share this post


Link to post
Share on other sites
MrMitchell

Try "$oOMail.From" ?

Share this post


Link to post
Share on other sites
seandisanti

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...

Share this post


Link to post
Share on other sites
MrMitchell

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...

Share this post


Link to post
Share on other sites
seandisanti

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.

Share this post


Link to post
Share on other sites
MrMitchell

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...

Share this post


Link to post
Share on other sites
seandisanti

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.

Share this post


Link to post
Share on other sites
MrMitchell

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...

Share this post


Link to post
Share on other sites
seandisanti

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.

Share this post


Link to post
Share on other sites
MrMitchell

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...

Share this post


Link to post
Share on other sites
seandisanti

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

Share this post


Link to post
Share on other sites
MrMitchell

it would be under tools>macros>record macro if the functionality is there

In Outlook 2003 it is not available, it is for Word and Excel though.

Share this post


Link to post
Share on other sites
seandisanti

In Outlook 2003 it is not available, it is for Word and Excel though.

if you have word setup as your defaul email editor, you may be able to start creating a message, then start recording, etc...

Share this post


Link to post
Share on other sites
MrMitchell

if you have word setup as your defaul email editor, you may be able to start creating a message, then start recording, etc...

Posted Image Just tried,it's greyed out...bummer

Share this post


Link to post
Share on other sites
Juvigy

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.

Share this post


Link to post
Share on other sites
seandisanti

nice, i knew it was possible but thought that the behalf was just for delegates. I guess for a non exchange address that should do it.

Share this post


Link to post
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
Sign in to follow this  

×