Solved

Select outgoing email (from) address from list via VBA

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
exchange, outlook 2 36
Outlook Autoconfigures for On-Premise Exchange 1 40
Outlook 2013 Sync Errors from Exchnage 2010 NOT in cached mode 1 18
outlook 6 34
Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
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 …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

813 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

10 Experts available now in Live!

Get 1:1 Help Now