Link to home
Create AccountLog in
Avatar of Lambel
Lambel

asked on

Outlook Automation using VBA - misleading error message

I have an automated email process in MSAccess that lets the user select a recipient, and send out a pre-formated email message and attached report.

We recently changed exchange servers, and now when I send the email, I get a misleading message back saying it was unsuccessful.  But the email actually gets sent successfully.

Here is the message:

Your message did not reach some or all of the intended recipients.

Subject: PP Tax Report for 888888 - TEST
Sent: 12/27/2010 1:43 PM

The following recipient(s) could not be reached:

first.last@msn.com on 12/27/2010 1:44 PM

The e-mail system was unable to deliver the message, but did not report a specific reason. Check the address and try again. If it still fails, contact your system administrator.

< ServerName08.e2k.ad.xx.com #5.0.0 smtp; 5.1.0 - Unknown address error 550-'Requested action not taken: mailbox unavailable' (delivery attempts: 0)>

 

 

Private Sub Command4_Click()
Dim oApp As Outlook.Application
Dim objNewMail As Outlook.MailItem
Dim RS1 As Recordset
Dim RS2 As Recordset
Dim RS3 As Recordset
Set db1 = CurrentDb

' Me.List0  is the name of a textbox that lists the email recipients to choose from

Set RS1 = db1.OpenRecordset("select * from qryEmailAddys")
Set RS2 = db1.OpenRecordset("select * from PDFMessage")
Set RS3 = db1.OpenRecordset("select * from GlobalParameters")

If IsNull(Me.List0) Then
    MsgBox "Must select a customer to be e-mailed"
    Cancel = True
    Exit Sub
End If

Set oApp = CreateObject("Outlook.Application")
Set objNewMail = oApp.CreateItem(olMailItem)
statusbar1 = SysCmd(acSysCmdSetStatus, "Emailing PDF: " & Me.List0 & "To " & RS1![email])
  
    RS3.Edit
    RS3!FLEET = Me.List0
    RS3.Update

   With objNewMail
       .To = RS1![email]
       .Subject = "Tax Report " & Me.List0 & " - " & RS1![FleetName]
       .Body = RS2!Content1
       If Len(RS1!CC) <> 0 Then
            .CC = RS1!CC
        End If
        MsgBox ("Programmer note: The pdf file location has been redirected for testing")
        .Attachments.Add "C:\Tax\" & Me.List0 & ".pdf"
      
       .Save
       .Send
   End With

db1.Execute "qryUpdateHistoryEmail"


Set oApp = Nothing
Set objNewMail = Nothing
Set objOutlookRecip = Nothing

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of p912s
p912s
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Lambel
Lambel

ASKER

I followed up your comments and talked to IT about changes to the server.  The server moved off-site. Messages are now required to go through additional intermediary steps before getting to the new smtp server.  Thanks for your responses.
Lynn
You're welcome.
You're welcome!