Change the From Field

非 Y 不嫁゛ 提交于 2019-12-25 14:00:29

问题


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.


回答1:


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.




回答2:


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 - 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.



来源:https://stackoverflow.com/questions/33322540/change-the-from-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!