Results 1 to 4 of 4
  1. #1
    TerraEarth is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    86

    Restrictions in Outlook Automation? How to deal with failed cases?

    I recently finished setting up a Outlook automation program that populates emails with subject, body, address, etc. and attaches a PDF attachment through a name-lookup in a directory that holds many pdfs.



    On one run I attempted to send two emails to myself yet one of the emails were never received, every single subsequent test run after this resulted in 0 failures. Is there some way to figure out whether or not a email has arrived or not at its destination or if there was some sort of error?

    Secondly, I was wondering if you guys knew of any restrictions running this sort of program. I could easily imagine this being used for spam-purposes; are there safeguards against this built into access/vba/outlook? And if so what is the best way to work around it? Are there any hidden considerations that I may not have touched upon that more experienced users may be able to shed some light on for me in terms of potential pitfalls or hazards to this sort of program?

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,829
    Arrived? not that I know of - beyond a read receipt, which the recipient does not have to provide
    Restrictions for this sort of program? Without seeing it, hard to tell. The 5 second delay message for sending some emails from Access gets circumvented in a few ways, some more complicated than others (COM). I don't know of any safeguards beyond what an email server might impose on a connection/IP, so yes, spamming is possible, until you get blacklisted.
    Are there any hidden considerations that I may not have touched upon... - again, without seeing, hard to tell. However, I can say that if you've ever been caught in a continuous loop, you can imagine what can happen if this happens to you during email sending. That's why I always used recordsets to determine the count of emails and set a loop counter accordingly. The number of emails sent by the db on a daily basis was not large because they were for non-conforming nags, but if there were only 10 records, I didn't want anyone calling me to say they suddenly had thousands of emails in their inbox. So once the loop reached that count, it was exiting regardless and I figured someone would let me know they got x number of emails for the same thing.

    That's all I can think of.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    TerraEarth is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2018
    Posts
    86
    My program is quite straightforward, it creates a recordset and for each entry in the recordset until the .EOF of the recordset it pulls the names/emails/etc. and populates a outlook mailitem via the outlook library. It then attaches a pdf and sends it. If you guys could point out any improvements that might be made or issues i might run into, it would be appreciated.

    I plan on testing it out and making adjustments as I go along.

    Code:
    Option Compare Database
    
    
    Private Sub EmailTest()
    
    
    Dim dbs As Database
    Dim rstEmailList As Recordset
    Dim oOutlook As Outlook.Application
    Dim oOutlookMsg As Outlook.MailItem
    Dim oOutlookRecip As Outlook.Recipient
    Dim oOutlookAttach As Outlook.Attachment
    Dim EmailAddress As String
    Dim FilePath As String
    Dim IndexCounter As Integer
    
    
    Set dbs = CurrentDb
    Set rstEmailList = dbs.OpenRecordset("tbl")
    
    
    rstEmailList.MoveFirst
    
    
    Set oOutlook = CreateObject("Outlook.Application")
    Do Until rstEmailList.EOF
    
    
    Set oOutlookMsg = oOutlook.CreateItem(olMailItem)
    FilePath = "C:\Users\RandomDirectory\" & rstEmailList![DocumentID] & ".pdf"
    oOutlookMsg.Attachments.Add (FilePath)
    EmailAddress = rstEmailList![POCEmail]
    
    
    With oOutlookMsg
        Set oOutlookRecip = .Recipients.Add(EmailAddress)
        oOutlookRecip.Type = olTo
        .Subject = "document#: " & rstEmailList![DocumentID]
        .Body = "Hello " & rstEmailList![POCName] & ", Please review the attached PDF!"
        .Send
        Debug.Print ("Email#: " & rstEmailList![DocumentID] & " was sent!") 'for tracking email progress in console
    End With
    rstEmailList.MoveNext
    Loop
    
    
    Debug.Print ("#################### END SESSION ####################")
    Set oOutlookMsg = Nothing
    Set oOutlook = Nothing
    End Sub

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,829
    On my phone so will be succinct. To me these are concerns:
    You don't have Option Explicit which should be at the top of every module. Seems you haven't set the option to require variable declaration. On that note, is "tbl" really as written?

    Moving first on an empty recordset will cause an error. Should test or ensure there are records.
    You have no error handling routine.
    That's it for now.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 03-31-2018, 04:38 PM
  2. Outlook Automation Hanging On Address Book
    By Soule in forum Programming
    Replies: 3
    Last Post: 03-03-2012, 03:04 PM
  3. restrictions for different users
    By joe1987 in forum Access
    Replies: 7
    Last Post: 12-11-2011, 05:05 PM
  4. Replies: 0
    Last Post: 02-23-2011, 10:32 PM
  5. Outlook Object Model question - automation
    By yeah in forum Programming
    Replies: 1
    Last Post: 11-23-2010, 02:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums