Solved

Select outgoing email (from) address from list via VBA

Posted on 2014-01-25
7
853 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 52

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 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