.Send无法使用时,如何发送邮件? [英] How to send mail when the .Send does not work?

查看:71
本文介绍了.Send无法使用时,如何发送邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过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:\test.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 >>文件选项卡>>选项>>信任中心>>信任中心设置>>程序访问中。 – 1小时前的Sorceri

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部门的说法,您可能或可能无法更改这些设置。例如,在我当前的工作中,我只能自动显示电子邮件,而不能通过代码发送电子邮件。网络安全团队将不允许这样做。 – 56分钟前斯科特·霍尔茨曼(Scott Holtzman)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆