Is there a way to verify that an email was sent?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    Is there a way to verify that an email was sent?

    I'm using the following code to send emails from my database:
    Code:
    Public Sub SendEmail(strSubject As String, strText As String, _
                    strTo As String, Optional strFrom As String)
    
    Dim cdoConfig As Object
    Dim msgOne As Object
    
    Set cdoConfig = CreateObject("CDO.Configuration")
    With cdoConfig.Fields
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = 25
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Exchange.ftc.com"
        .Update
    End With
    
    If strFrom & "" = "" Then strFrom = "Database_Notification@fountaintrust.com"
    
    Set msgOne = CreateObject("CDO.Message")
    Set msgOne.Configuration = cdoConfig
        
    With msgOne
        .To = strTo
        .From = strFrom
        .Subject = strSubject
        .TextBody = strText
        .Send
    End With
    
    Set cdoConfig = Nothing
    Set msgOne = Nothing
    
    End Sub
    I would like to be able to verify that the email was sent. I know that delivery confirmation requests can be used, but that is dependent on the receiver allowing it to be sent so it isn't totally dependable.

    The other idea that I had was change it from a sub to a function and use it as a flag of some sort. I would just have to trust that since the email addresses are saved in the database that they are accurate. If there was an error going through the code, then the error handler would set the function to 1. If the function didn't have an error, then the function would return a 0. Is this a valid idea or does it make me worthy of brain surgery to fix the cobwebs in my brain?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    If the code runs without error then the e-mail was probably sent.

    Whether or not it arrived at it's destination is another question. If you don't get an e-mail saying that the mail server was not found, then it probably arrived at it's destination.

    And whether or not the target opened it is yet another question. You could use read confirmations, but that's not accurate. Some people use a 1x1 image that is linked to the server by an ID to find out if an e-mail was opened. But some e-mail applications block images from loading for that very purpose. So that's not completely reliable either but is more so than the other option.

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      ahh... think I just found my reference link:
      Sending mail from Excel with CDO
      I know... it says Excel; however, it covers the CDO method.

      In an excel add-in that I have, I use this method to send error messages to me. We used to use "Groupwise" as our email... here I was looking thru my Access references and it was from my old Excel97 work.

      Comment

      • Seth Schrock
        Recognized Expert Specialist
        • Dec 2010
        • 2965

        #4
        So basically, I can use my function idea to make sure that the code ran without an error. This would mean that the email was sent. I guess I can play with delivery notifications and see what that tells me.

        Is there a way to trap for an error of a bad email address? Maybe I just need to add a reply to address so that delivery errors get sent to me by coding my email address into the reply to address.

        Comment

        Working...