如何更改我的电子邮件帐户发件人"来自"在vba的前景

时间:2018-02-12 22:44:57

标签: vba outlook outlook-vba

我的Outlook中有2个电子邮箱帐户,因此当我发送电子邮件时,如何更改电子邮件帐户

"From"

enter image description here

Enter image description here

我需要发送电子邮件地址" anas3643@hotmail.com"

Sub Test_for_using()
'MVP OShon from VBATools.pl
    Dim oMail  As MailItem
    On Error GoTo blad
    Select Case TypeName(Application.ActiveWindow)
    Case "Explorer":  Set oMail = ActiveExplorer.Selection.Item(2)
    Case "Inspector": Set oMail = ActiveInspector.CurrentItem
    Case Else: Exit Sub
    End Select
    Call odpowiedz_do_nadawcy(oMail)
    blad:
End Sub

Sub odpowiedz_do_nadawcy(Item As Outlook.MailItem)
    Dim oReply As MailItem
    With Item
        Set oReply = .Forward
        Dim MyValue As Integer
        Dim x As String
        Dim emailNames(19) As String
        emailNames(1) = "anas.alwasel11@gmail.com"
        emailNames(2) = "anas3643@hotmail.com"
        emailNames(3) = "anas.alwasel11@gmail.com"
        emailNames(4) = "anas3643@hotmail.com"
        emailNames(5) = "anas.alwasel11@gmail.com"
        emailNames(6) = "anas3643@hotmail.com"
        emailNames(7) = "anas.alwasel11@gmail.com"
        emailNames(8) = "anas3643@hotmail.com"
        emailNames(9) = "anas.alwasel11@gmail.com"
        emailNames(10) = "anas3643@hotmail.com"
        emailNames(11) = "anas.alwasel11@gmail.com"
        emailNames(12) = "anas3643@hotmail.com"
        emailNames(13) = "anas.alwasel11@gmail.com"
        emailNames(14) = "anas3643@hotmail.com"
        emailNames(15) = "anas.alwasel11@gmail.com"
        emailNames(16) = "anas3643@hotmail.com"
        emailNames(19) = "anas3643@hotmail.com"

        MyValue = CInt(Int((19 * rnd()) + 1))     ' Generate random value between 1 and 6.
        x = emailNames(MyValue)
        oReply.Forward
        oReply.Recipients.Add (x)
        oReply.Send
        Set oReply = Item

    End With

End Sub

1 个答案:

答案 0 :(得分:1)

  

MailItem.SendUsingAccount 属性

     

返回或设置代表其下帐户的Account对象   其中MailItem将被发送。 (读/写)。

     

语法

     

expression . SendUsingAccount

     
      
  • expression :返回MailItem对象的表达式。
  •   
     

<强>说明

     

SendUsingAccount属性可用于指定帐户   应该用MailItem方法发送Send   调用。如果为该帐户指定的帐户,此属性将返回Null   MailItem已不复存在。