I am writing a batch email procedure (note this is multiple emails to individuals done through a loop, not 1 email to a lot of people) and I keep getting a 287 error when I use ".Send" but ".Display" is working just fine. I've provided two bare bone code examples for simplicity sake below; both throw a 287 error.
I've also tried the "DoCmd.SendObject" function shown below, but get outlook security prompts (which are docmd.setwarning proof as far as I can tell) for each and every email. To add, they are not even the "time allowance" prompt that allow access for "x" minutes.
Does anyone know what's going on below and/or had any luck with batch emails like this in the past?
Thanks
Code:
Sub mailTest()
Dim oApp As outlook.Application
Set oApp = New outlook.Application
Dim oMI As outlook.MailItem
Dim x As Integer
For x = 1 To 2
Set oMI = oApp.CreateItem(olMailItem)
oMI.Body = "test message"
oMI.Subject = "message from access"
oMI.To = "email" & x & "@test.com"
oMI.Send '.Display works fine
Next x
Set oMI = Nothing
Set oApp = Nothing
End Sub
Code:
Sub mailTestTwo()
Dim OutApp As Object
Dim OutMail As Object
Dim x As Integer
Set OutApp = CreateObject("Outlook.Application")
For x = 1 To 2
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = "email" & x & "@test.com"
.CC = ""
.BCC = ""
.Subject = "Test"
.Body = "Test Bod"
.Send 'Display works
End With
Next x
Set OutApp = Nothing
Set OutMail = Nothing
End Sub
This throws the outlook prompt every time to allow sending
Code:
DoCmd.SendObject acSendNoObject, , , test@test.com, , , "Test - " & Date, bodyStr, False 'False to send, True to display