【发布时间】:2012-05-23 01:43:40
【问题描述】:
我的客户想要将 excel/vba 分发给他的客户,vba 将自动发送电子邮件。
也许发件人应该是其他帐户,而不是使用 vba 的人的 Outlook 帐户,因为电子邮件中可能包含一些私人内容。真的有可能吗?
另一件事是在自动执行此类任务时臭名昭著的弹出警告。我听说 Application.SendKeys 在计算机锁定时并不总是有效。
CDO 是如何完成这项任务的?
【问题讨论】:
我的客户想要将 excel/vba 分发给他的客户,vba 将自动发送电子邮件。
也许发件人应该是其他帐户,而不是使用 vba 的人的 Outlook 帐户,因为电子邮件中可能包含一些私人内容。真的有可能吗?
另一件事是在自动执行此类任务时臭名昭著的弹出警告。我听说 Application.SendKeys 在计算机锁定时并不总是有效。
CDO 是如何完成这项任务的?
【问题讨论】:
在您最初的问题中,您可以在 Outlook 中使用 MailItem.SentOnBehalfOfName
关于安全警告,Outlook 的标准两种解决方案是:
1) 使用Clickyes
2) 安装Outlook Redemption
【讨论】:
您不必使用 Outlook 发送电子邮件。如您所见,CDO 无需使用 Outlook 即可工作。
这里有一些代码可以帮助您入门。
Public Sub SendEmail(Subject As String, Body As String, ToPerson as String)
Dim iCfg As Object
Dim iMsg As Object
Set iCfg = CreateObject("CDO.Configuration")
Set iMsg = CreateObject("CDO.Message")
With iCfg.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "email-account"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
.Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = "account@domain.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
End With
With iMsg
.Configuration = iCfg
.Subject = Subject
.TextBody = Body
.To = ToPerson
.Send
End With
Set iMsg = Nothing
Set iCfg = Nothing
End Sub
【讨论】: