【问题标题】:Sending email from different account VBA从不同帐户 VBA 发送电子邮件
【发布时间】:2020-11-19 01:30:45
【问题描述】:

尝试使用 VBA 发送电子邮件,但尽管尽了最大努力,它仍然从我的个人电子邮件地址发送。请有人建议如何从辅助电子邮件地址发送?

Sub Send_Mail()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Send_Mail")
Dim I As Integer

Dim OA As Object
Dim msg As Object

Set OA = CreateObject("outlook.application")
Set OutAccount = OA.Session.Accounts.Item(2)

Dim last_row As Integer
last_row = Application.CountA(sh.Range("A:A"))

For I = 2 To last_row
    Set msg = OA.CreateItem(0)
    msg.SendUsingAccount = OutAccount
    msg.To = sh.Range("B" & I).Value
    msg.cc = sh.Range("D" & I).Value
    msg.Subject = sh.Range("E" & I).Value
    msg.body = sh.Range("F" & I).Value
            
    If sh.Range("G" & I).Value <> "" Then
        msg.attachments.Add sh.Range("G" & I).Value
            
End If
    
msg.send
    
sh.Range("H" & I).Value = "Sent"

Next I

MsgBox "All emails sent successfully"

End Sub

谢谢!

【问题讨论】:

标签: excel vba outlook


【解决方案1】:

您可以使用 .From 设置您要从哪个电子邮件帐户发送邮件。

strFrom = Name & "<" & Email & ">"
msg.From = strFrom

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-24
  • 1970-01-01
  • 2016-11-22
  • 2012-03-24
  • 1970-01-01
  • 2022-08-10
相关资源
最近更新 更多