Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Select outgoing email (from) address from list via VBA

Posted on 2014-01-25
7
Medium Priority
?
865 Views
Last Modified: 2014-02-04
I'm using Outlook 2007.

I have several email addresses (cox, google, work, ...), all of which get forwarded to my primary email address (cox)

When I respond to these messages, or when I create a new message, I can fill in the From: address to use the specific address I want as my Sending address.  But I prefer not to display the FROM box and have to type in the outgoing email address

What I would like to happen, is that when I click send, Outlook will popup a form with a list of possible outgoing email addresses allowing me to simply click the appropriate address, and complete the send operation using the Click event of the listbox.

I am an Access and Excel VBA programmer, so I am very familiar with VBA, but am totally unfamiliar with the Outlook object model.  So what I need to know is:

1.  what event I should use to popup this form, after I hit send and before the email is actually leaves my system, and
2. what properties of the mail item do I need to set (.From)
3. How to proceed with the send operation.  I'm assuming if I open the popup form with an acWindowDialog argument, it will pause the process and simply hiding the form would allow me to continue the code, capture the info from the form, update the mail items .From property, and then close the form.
0
Comment
Question by:Dale Fye
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39808574
Hi,

See example here

You could change the Default  Sender in the send event
http://msdn.microsoft.com/en-us/library/office/bb220221(v=office.12).aspx

to find the right account
refer to
http://msdn.microsoft.com/en-us/library/office/bb207787(v=office.12).aspx

Regards
0
 
LVL 48

Author Comment

by:Dale Fye
ID: 39808633
Rgonzo,

not seeing it.  The first talks about the MailItem.Send event,  but when I'm in the Outlook VBA editor, I don't see that Application event.

What I have right now is:

1.  Userform (frm_From) with list box

2.  Code in the Application_ItemSend event
      a.  pops up the form with list populated using the Form_Initialize event and addItem methods
      b. User selects an item from the list (double click) or Click in the list and click on Close button.  Either of these events hides the userform
      c.  code in Application_ItemSend continues by executing a debug.print of the value of the selected item in the list
      d.  Unload the form

3.  But neither of those examples explains how to set the From property of the outgoing email item.  I've found references to the To, CC, BCC properties of the email, but not the From property on the MSDN sight.
0
 
LVL 48

Author Comment

by:Dale Fye
ID: 39808655
BTW, the Application_ItemSend event has two arguments:

Item as Object
Cancel as Boolean

I've tried:

Item.sendonbehalfof = frm_From.lst_From.value

but receive the Run-time error 438 (Object doesn't support this property or method)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 76

Expert Comment

by:David Lee
ID: 39809425
Hi, fyed.

Do you want to select the account the message is sent through or just fill in the from address?
0
 
LVL 48

Author Comment

by:Dale Fye
ID: 39809455
Either would be acceptable, I assumed just using the email address would be easier.

I assume that the difference is that if I just set the FROM address, the people I'm emailing will simply get email where the From address looks the way I want in the email list view, but when you open the email the from would look like:

From: Dale Fye [Dale.Fye@xyz.net] on behalf of dale@abc.com

Which is a bit confusing, when all you want them to see is dale@abc.com

I don't even have separate accounts setup at the moment.  The various other email servers are all setup to auto forward to my personal account.  Would like to setup a separate account for at least one of those though.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 39809470
See this post from a question I participated in a few years ago.  It shows how to do this using the "send on behalf of" method.  There's an earlier post in the same question where I show how to set the account the message will be sent through.
0
 
LVL 48

Author Closing Comment

by:Dale Fye
ID: 39833698
d_lee,

Decided to simply display the From box in the Outlook new mail dialog.  I'm sure I'll get back to this eventually, and the code you provided, particularly the stuff about selecting the account to send email through is what I was looking for.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Read this checklist to learn more about the 15 things you should never include in an email signature.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question