vba - 从其他用户发送电子邮件

时间:2012-05-23 01:43:41

标签: vba excel-vba outlook-vba excel

我的客户希望将excel / vba分发给他的客户,vba会自动发送电子邮件。

也许发件人应该是其他帐户,而不是使用vba的人的Outlook帐户,因为某些私人资料可能在电子邮件中。真的有可能吗?

另一件事是在自动执行此类任务时臭名昭着的弹出警告。我听说当计算机被锁定时,Application.SendKeys并不总是有效。

CDO如何完成这项任务?

2 个答案:

答案 0 :(得分:1)

在您的初始问题上,您可以使用MailItem.SentOnBehalfOfName与Outlook

在安全警告上,Outlook的标准两种解决方案是:
1)使用Clickyes
2)安装Outlook Redemption

答案 1 :(得分:0)

您不必使用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
相关问题