PDA

View Full Version : Send from default account



llldebaserll
12-08-2015, 10:56 AM
I'm sure this is probably somewhere in the forum but I can't find anything for the life of me.


I have a VBA macro set up creating emails and sending on behalf of various parties (using the .SendOnBehalfOfName property).
But there are a few instances where I want the emails created to be sent from the user's account.
But if I choose to not set the .SendOnBehalfOfName property, the From box is left blank and the user must manually enter in their email address.

Is there a way I can have the From box populated with the user's default Outlook address?

Below is the code I am using to determine whether to use the .SentOnBehalfOfName property or not. It pulls an email address from an .txtINI file. But if that user's .txtINI file preferences has a blank, I would like it to just default to their own email address.


If EmailFrom <> "" Then outmail.SentOnBehalfOfName = EmailFrom

Any help is greatly appreciated!

gmayor
12-08-2015, 11:56 PM
I am not using an Exchange account here, so I cannot test this, but I expect it should be something like the following (assuming you are programming in Outlook itself).


Dim olNS As Outlook.NameSpace
Dim olAccount As Outlook.Account
Dim strAccount As String

Set olNS = GetNamespace("MAPI")
strDefaultAcct = olNS.Accounts.Item(1)
For Each olAccount In olNS.Accounts
If olAccount.DisplayName = strDefaultAcct Then
outMail.SendUsingAccount = olAccount
Exit For
End If
Next olAccount
If Not EmailFrom = "" Then outMail.SentOnBehalfOfName = EmailFrom