Solved

Select outgoing email (from) address from list via VBA

Posted on 2014-01-25
7
835 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 (Access MVP)
  • 4
  • 2
7 Comments
 
LVL 49

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 47

Author Comment

by:Dale Fye (Access MVP)
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 47

Author Comment

by:Dale Fye (Access MVP)
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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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 47

Author Comment

by:Dale Fye (Access MVP)
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 47

Author Closing Comment

by:Dale Fye (Access MVP)
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Resolve DNS query failed errors for Exchange
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
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 …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now