Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 从Outlook中的其他电子邮件地址发送_Vba_Email_Outlook - Fatal编程技术网

Vba 从Outlook中的其他电子邮件地址发送

Vba 从Outlook中的其他电子邮件地址发送,vba,email,outlook,Vba,Email,Outlook,“我的用户”将其个人邮箱作为其主帐户,并在其Outlook 2010客户端中配置了自动映射的共享邮箱。共享邮箱是Office 365共享邮箱,因此无法登录以将其设置为主帐户 我正在尝试从共享帐户的地址开始新的电子邮件 下面是我一直尝试使用的VBA代码。我允许在Outlook的信任中心设置中使用宏 Public Sub New_Mail() Dim oAccount As Outlook.Account Dim oMail As Outlook.MailItem For Each oAccount

“我的用户”将其个人邮箱作为其主帐户,并在其Outlook 2010客户端中配置了自动映射的共享邮箱。共享邮箱是Office 365共享邮箱,因此无法登录以将其设置为主帐户

我正在尝试从共享帐户的地址开始新的电子邮件

下面是我一直尝试使用的VBA代码。我允许在Outlook的信任中心设置中使用宏

Public Sub New_Mail()
Dim oAccount As Outlook.Account
Dim oMail As Outlook.MailItem
For Each oAccount In Application.Session.Accounts
    If oAccount = "sharedMailboxAddress@domain.tld" Then
        Set oMail = Application.CreateItem(olMailItem)
        oMail.SendUsingAccount = oAccount
        oMail.Display
    End If
Next
End Sub

什么在代码中不起作用

使用
smtpAddress
属性选择帐户

示例函数:

Private Function GetAccountForEmailAddress(smtpAddress As String) As Outlook.account
    Dim account As Outlook.account

    For Each account In Application.Session.accounts
        If LCase(account.smtpAddress) = LCase(smtpAddress) Then
            Set GetAccountForEmailAddress = account
            Exit Function
        End If
    Next account

    MsgBox "No Account with SmtpAddress: " & smtpAddress & " exists!", vbCritical, "Oops!"

    Set GetAccountForEmailAddress = Nothing
End Function

什么在代码中不起作用

使用
smtpAddress
属性选择帐户

示例函数:

Private Function GetAccountForEmailAddress(smtpAddress As String) As Outlook.account
    Dim account As Outlook.account

    For Each account In Application.Session.accounts
        If LCase(account.smtpAddress) = LCase(smtpAddress) Then
            Set GetAccountForEmailAddress = account
            Exit Function
        End If
    Next account

    MsgBox "No Account with SmtpAddress: " & smtpAddress & " exists!", vbCritical, "Oops!"

    Set GetAccountForEmailAddress = Nothing
End Function

debug.print行将显示帐户

Option Explicit

Public Sub New_Mail()

Dim oAccount As account
Dim oMail As mailItem

For Each oAccount In Session.Accounts
    Debug.Print oAccount
    If LCase(oAccount) = LCase("text copied from the immediate window") Then
        Set oMail = CreateItem(olMailItem)
        oMail.SendUsingAccount = oAccount
        oMail.Display
    End If
    Next

ExitRoutine:
    Set oMail = Nothing

End Sub

debug.print行将显示帐户

Option Explicit

Public Sub New_Mail()

Dim oAccount As account
Dim oMail As mailItem

For Each oAccount In Session.Accounts
    Debug.Print oAccount
    If LCase(oAccount) = LCase("text copied from the immediate window") Then
        Set oMail = CreateItem(olMailItem)
        oMail.SendUsingAccount = oAccount
        oMail.Display
    End If
    Next

ExitRoutine:
    Set oMail = Nothing

End Sub

代理邮箱将不在命名空间.帐户列表中


改为设置
MailItem.SentonBehalfName
属性。

代理邮箱将不在命名空间.帐户列表中


改为设置
MailItem.SentonBehalfName
属性。

将以下代码与SentonBehalfName属性一起使用,从共享邮箱的地址启动新电子邮件。感谢Dmitry Streblechenko为我指明了正确的方向

Sub New_Mail()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)


 With objMsg
  .SentOnBehalfOfName = "sharedMailboxAddress@domain.tld"
  .Display
End With

Set objMsg = Nothing
End Sub

将以下代码与SentOnBehalfOfName属性一起使用可从共享邮箱的地址启动新电子邮件。感谢Dmitry Streblechenko为我指明了正确的方向

Sub New_Mail()
Dim objMsg As MailItem
Set objMsg = Application.CreateItem(olMailItem)


 With objMsg
  .SentOnBehalfOfName = "sharedMailboxAddress@domain.tld"
  .Display
End With

Set objMsg = Nothing
End Sub

VB.NET与VBA/Office宏无关。VB.NET与VBA/Office宏无关。当我尝试运行代码时,不会发生任何情况,也不会出现任何错误。我在代码上方添加了您的函数,但在运行时仍然没有发生任何事情。在执行VBA行后,标记一行代码以启动VBA调试器。这可能是了解发生了什么的唯一方法。当我尝试运行代码时,不会发生任何事情,也不会给出任何错误。我在代码上方添加了您的函数,但在运行时仍然没有发生任何事情。在执行VBA行后,标记一行代码以启动VBA调试器。也许这是唯一能知道发生了什么的方法。