.Send 不起作用时如何发送邮件? [英] How to send mail when the .Send does not work?
问题描述
我正在尝试通过 VBA 发送电子邮件.
I am trying to send email through VBA.
当 .Send 不起作用时,我发现 Sendkeys 方法有效但电子邮件必须显示,然后您无法触摸计算机,否则您可能会破坏宏.
When the .Send wouldn't work, I found the Sendkeys method which works but the email has to display and then you can't touch the computer or you may disrupt the macro.
如何使 .Send 方法起作用?
How can I make the .Send method work?
Dim OutApp As Object
Dim OutMail As Object
Dim count As Integer
EmailTo = Worksheets("Email Addresses").Range("A2")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItemFromTemplate( _
Sheets("Start Here").Range("B25"))
On Error Resume Next
With OutMail
.To = EmailTo
'.CC = ""
'.BCC = ""
'.Subject = ""
'.Body = ""
'.Attachments.Ad' ActiveWorkbook.FullName
' You can add other files by uncommenting the following line.
'.Attachments.Add ("C: est.txt")
' In place of the following statement, you can use ".Display" to
' display the mail.
'.Display
'SendKeys "^{ENTER}" ' <---this was the fix I found when .Send didn't work
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
推荐答案
您的电子邮件安全设置最有可能导致该问题.在 Outlook>>文件选项卡>>选项>>信任中心>>信任中心设置>>程序访问.– Sorceri 1 小时前
Your email security settings are what is most likely causing the issue. In outlook>>File tab>>Options>>Trust Center>>Trust Center settings>>Programmatic Access. – Sorceri 1 hour ago
根据@Sorceri 所说,根据 IT 部门的说法,您可能会或可能无法更改这些设置.比如我现在的工作,只能自动显示邮件,不能通过代码发送.网络安全团队不会允许的.– Scott Holtzman 56 分钟前
In line with what @Sorceri said, you may, or may not be able to change those settings, according to IT department. For example, in my current job, I can only display emails automatically, but cannot send them through code. Cyber-Security team will not allow it. – Scott Holtzman 56 mins ago
因此,结论似乎是 SendKeys 是最佳选择,因为由我的 IT 部门控制的安全设置已将我锁定在信任设置中的编程访问之外.
So it seems like the verdict is that the SendKeys is the best option because security settings that are controlled by my IT department have locked me out of the programmatic access in trust settings.
感谢@Sorceri 和@Scott Holtzman
Thank you to @Sorceri and @Scott Holtzman
这篇关于.Send 不起作用时如何发送邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!