VBA Outlook Automation - Won't send E-Mail

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    VBA Outlook Automation - Won't send E-Mail

    Hey Friends,

    This one either has to be incredibly simple or impossible to solve: Here is some sample code:

    Code:
    Public Function SendEMail()
        Dim olApp As Outlook.Application
        Dim olMail As Outlook.MailItem
        Set olApp = CreateObject("Outlook.Application")
        Set olMail = olApp.CreateItem(olMailItem)
        With olMail
            .To = "Name@Domain.mail"
            .Body = "Test"
            .Subject = "Test"
            .Send
        End With
    End Function
    Pretty simple, right? Everywhere I look to see how to use this automation feature, this is exactly how it says to do it. But, whenever I get to the .Send line, I get error number 287: "Applicatio n-defined or object-defined error."

    What am I doing wrong?

    If I replace ".Send" with ".Display", all works well and I can just click send. However, this is part of a block of code that cycles through dozens of records, and I would prefer to have Outlook send the e-mail without having to click send.

    Not a big deal, but incredibly mystifying! Any suggestions? BTW, everything is properly referenced.

    I'm stumped!
  • 9815402440
    New Member
    • Oct 2007
    • 180

    #2
    nothing is wrong in the code. you might have antivirus installed. check email settings in advance settings of antivirus.

    -----------------------
    Manpreet Singh Dhillon

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3653

      #3
      Manpreet,

      Makes sense. This may be the "best answer" for the issue, but it just means that I have no solution, as our anti-virus is managed at an enterprise level, which means it practically takes an act of Congress to make changes to it.

      At least I understand what the issue is, and it is not a coding error. Thank you for your reply!

      Greg

      Comment

      Working...