Solved

Select outgoing email (from) address from list via VBA

Posted on 2014-01-25
7
833 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 48

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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

20 Experts available now in Live!

Get 1:1 Help Now