【问题标题】:vba - sending email from a different uservba - 从不同的用户发送电子邮件
【发布时间】:2012-05-23 01:43:40
【问题描述】:

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

也许发件人应该是其他帐户,而不是使用 vba 的人的 Outlook 帐户,因为电子邮件中可能包含一些私人内容。真的有可能吗?

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

CDO 是如何完成这项任务的?

【问题讨论】:

标签: excel vba outlook


【解决方案1】:

在您最初的问题中,您可以在 Outlook 中使用 MailItem.SentOnBehalfOfName

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

【讨论】:

  • + 1 :) 还有第三个选项。降低 Outlook 中的安全性。我已经做到了,我不再看到那些弹出窗口(我使用的是 Off-2010)
  • @SiddharthRout 只要你知道这是不推荐的。
  • @JP:是的,在共享 PC 上绝对不推荐。但是在我的个人笔记本电脑上,其他人可以访问 + 它受到最新 AV 软件的全面保护 + 我小心不要打开任何未知的宏文件,我没有看到任何问题 :)
【解决方案2】:

您不必使用 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

【讨论】:

  • 我不再有原始来源。这是我在一个项目中使用的代码。
猜你喜欢
  • 1970-01-01
  • 2015-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多