X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
> Send Multiple Emails Via Gmail With Separate Attachments For Each Email, Any Version    
post Jul 26 2019, 09:21 AM

Posts: 5,573
Joined: 2-November 04
From: Downey, CA

This isn't an Outlook question per se, I have a list of 100+ employees that I need to send an individual e-mail to each employee with 2 .pdfs attached per e-mail, per employee - I can take the time to set up a table with all e-mail attachments and references if necessary - I couldn't find the answer on the 'net, especially for GMAIL - I have used code before to send out individual e-mails, but not this - I'm thinking of setting up an excel worksheet with each employee's email in col A, one of the .pdf's in col B and the other (which actually was an excel file before being converted to .pdf, and saying something like attachment (the value in B2) - I've done something similar to this before, but never like this - before, I had to send a daily e-mail to one person, and several people were copied on the e-mail, but they were hard-coded in my VBA code, and this was using access

Any ideas ?

Thanks in advance....

Go to the top of the page
Start new topic
post Jul 26 2019, 11:44 AM

Posts: 2,688
Joined: 4-February 07
From: USA, Florida, Delray Beach

  1. This is a relatively simple matter if Outlook is your E-Mail Client.
  2. Let's assume that you have the following Data in Sheet1 with Column A being the Employee's Name, Column B being his/her E-Mail Address, Column C the first File to attach, and Column D being the second File to attach.
    John Doe    JDoe@Aol.com      C:\Test\Test2.pdf     C:\Test\Test1.pdf
    Peter Pan   PPan@Comcast.net  C:\Test\Test3.pdf     C:\Test\Test4.pdf
    Fred Lee    FLee@Yahoo.com    C:\Test\Test6.pdf     C:\Test\Test5.pdf
  3. The following Code will process each Employee sending him/her a Name related E-Mail with the appropriate Attachments. The Code assumes that the Names in Column A are continuous with no 'Gaps.
  4. The following Code uses Early Binding but you could also Late Bind if preferred.
    Dim oLook  As Outlook.Application
    Dim oMail  As Outlook.MailItem
    Dim olns As Outlook.Namespace
    Dim sht As Excel.Worksheet
    Dim intRow As Integer

    Set sht = ActiveWorkbook.Worksheets("Sheet1")
    Set oLook = New Outlook.Application
    Set oMail = oLook.CreateItem(olMailItem)
    Set olns = oLook.GetNamespace("MAPI")

    intRow = 1      '1st Row with Data in it

    With sht
      Do While .Cells(intRow, "A") <> ""
       Set oMail = oLook.CreateItem(olMailItem)
        oMail.Subject = "Attached Files for Employee " & .Cells(intRow, "A")
        oMail.Body = "Please read the following Documentation which explains in detail " & _
                     "your new Medical Benefits Package"
        oMail.To = .Cells(intRow, "B")
        oMail.Attachments.Add CStr(.Cells(intRow, "C"))
        oMail.Attachments.Add CStr(.Cells(intRow, "D"))
            intRow = intRow + 1
    End With

    Set oLook = Nothing
    Set oMail = Nothing
    Set olns = Nothing
  5. If GMail is your E-Mail Client then I do believe that matters would be more difficult.
Go to the top of the page

Posts in this topic

Custom Search

RSSSearch   Top   Lo-Fi    14th November 2019 - 06:56 AM