0

I have a single Outlook email set up on my Outlook account, let's say "example@xxx.com".

I have another "email account", let's say "alias@zzz.net", that serves as nothing more than a pointer to my @xxx.com account.

Outlook has no settings for the pointer account other than my ability to type it into the From field. I have Outlook set up to manually change the From field between @xxx.com and @zzz.net.

Because my @xxx.com email is the actual email, Outlook defaults to that email in the From field. I would like this to be the opposite, i.e. any email I send out has "alias@zzz.com in the From field.

I have attempted with the following code:

Public WithEvents myItem As Outlook.MailItem

Private Sub Application_ItemLoad(ByVal Item As Object)
    If (TypeOf Item Is MailItem) Then
        Set myItem = Item
    End If
End Sub

Private Sub FromField()
    With myItem
        .SentOnBehalfOfName = "alias@zzz.com"
        .Display
    End With
End Sub

Private Sub myItem_Open(Cancel As Boolean)
    FromField
End Sub

Placing the FromField sub into the Application_ItemLoad did not work.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
ExPerseides
  • 31
  • 1
  • 1
  • 3
  • Is that for an Exchange account? Do you mean you want the recipients to see the email coming from one of your alias (proxy) SMTP addresses? – Dmitry Streblechenko Oct 24 '15 at 21:15
  • So my undergraduate school gave us an email account for life - and yeah it is an exchange account, which I use as my primary email. My graduate school gave us an email pointer. My adviser doesn't like the fact that my email are coming from my old school domain, and is afraid it could confuse sponsors/vendors. [Here is specifically what I'm talking about](http://imgur.com/IqY4kHv) The top email is the actual account, and the bottom one is the alias I want all my emails to appear to be coming from. I just don't want to have to manually change this every time I send an email. – ExPerseides Oct 24 '15 at 22:24
  • Are these accounts on different servers? Or is that the same mailbox? – Dmitry Streblechenko Oct 24 '15 at 22:26
  • One is on my old school's exchange server. The other is [this](http://www.uh.edu/infotech/services/accounts/email/alias/index.php#http://www.uh.edu/infotech/services/accounts/email/alias/index.php), which points to my old school's account. – ExPerseides Oct 24 '15 at 22:38
  • Exchange server will not let you send as another account unless it is from the same server and you have a right to send on behalf of that user. Why not open both accounts in Outlook? – Dmitry Streblechenko Oct 24 '15 at 23:17
  • The second account isn't an account. It points back to the first. And outlook will definitely let me do this. I'm doing it manually, as you can see in the picture from the last comment. It's not a question of can I do it, but how do I automate this through a VBA macro. – ExPerseides Oct 24 '15 at 23:35
  • To clarify, I just need help getting a macro set up so that, every time I go to send an email, it populates the From field with the email account of my choosing. – ExPerseides Oct 24 '15 at 23:36
  • So it is the same Exchange mailbox and you have the primary SMTP address and a proxy address handled by the same mailbox? – Dmitry Streblechenko Oct 25 '15 at 01:14
  • Yup, that's the gist of it. I want the emails to automatically put the proxy address in the From field rather than the primary SMTP address. – ExPerseides Oct 25 '15 at 02:39

2 Answers2

0

You need to use the SendUsingAccount property of the MailItem class which allows to set an Account object that represents the account under which the MailItem is to be sent.

Sub SendUsingAccount() 
 Dim oAccount As Outlook.account 
 For Each oAccount In Application.Session.Accounts 
  If oAccount.AccountType = olPop3 Then 
   Dim oMail As Outlook.MailItem 
   Set oMail = Application.CreateItem(olMailItem) 
   oMail.Subject = "Sent using POP3 Account" 
   oMail.Recipients.Add ("someone@example.com") 
   oMail.Recipients.ResolveAll 
   oMail.SendUsingAccount = oAccount 
   oMail.Send 
  End If 
 Next 
End Sub 

The SentOnBehalfOfName property makes sense only in case of Exchange account. Moreover, you need to have permissions to send emails on behalf of other accounts.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
0

Cannot do that - Exchange always uses the primary SMTP address when sending the outgoing messages. The only way to send as one of the proxy addresses is to do that through SMTP. You can either create a dummy POP3/SMTP account (make sure POP3 does not download the messages) or use Proxy Manager (I am its author) - it installs itself directly into Outlook and transparently uses SMTP under the hood.

See http://www.msoutlook.info/question/send-mail-from-additional-exchange-address-or-alias for the list of options.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78