简体   繁体   中英

Send Email outlook using Excel VBA

I am trying to send an email using Excel with this code:

Sub SEND_EMAIL()

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

' ADRESSE
olMail.To = "selojo7915@rippb.com"
' Subject
olMail.subject = "Line"
' BODY
olMail.body = "this"

olMail.Send

When starting this macro i have the following error

在此处输入图像描述

The error is in the last line (olMail.Send)

And every time i am trying to send an email outlook is starting to update and after a moment it's showing error

Exception de HRESULT: 0x80004004 (E_ABORT)

You see a security issue (earlier prompts) because Outlook is configured on the client computer in one of the following ways:

  • Uses the default Outlook security settings (that is, no Group Policy set up)
  • Uses security settings defined by Group Policy but does not have programmatic access policy applied
  • Uses security settings defined by Group Policy which is set to warn when the antivirus software is inactive or out of date

You can create a group policy to prevent security prompts from displaying if any up-to-date antivirus software is installed on the system or just turn these warning off (which is not really recommended).

Read more about that in the Security Behavior of the Outlook Object Model article.

You may consider using the following workarounds:

  • Install any antivirus software with latest updates.
  • Use a low-level API - Extended MAPI which doesn't trigger security issues. You may also consider Redemption which is a convenient wrapper around Extended MAPI.
  • Create a COM add-in which has access to the safe Application instance.
  • Use group policy settings to turn such security prompts/issues when dealing with Outlook.
  • Also you may consider using third-party components that allow turning off and on dynamically security prompts and issues in Outlook. See Outlook Security Manager for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM