Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access 2013 Sneding Email using Outlook - multiple addressees and multiple attachments

Status
Not open for further replies.

puforee

Technical User
Oct 6, 2006
741
US
I have been using send object to send email from my DB but I can only send one attachment at a time. I need to send more. I have found some articles about using Outlook coding in VB to do the job because it can handle more attachments.

Question: On the VB screen, in Access, on the tools menu - references what do I select to enable me to use the Outlook code?

Question: Can someone show me some code to send email to multiple people (just 2 for demo) using 2 attachment files that are stored in a folder outside of access.

I believe, in the code, there is also a command to show the email before it is sent. I think I saw it one time and I think it actually used the word Show

Any help and/or references to a complete dissertation on how to do this would be appreciated.

I am currently trying to send 2 and 3 attachments depending on selection and I don't want my users to have to add addresses 2 or 3 times.

OH, also, I might be able to select the To: addresses from the DB. Right now I don't have the email addresses to all the necessary people in the DB.

Thanks,

John
 
I use the below... Note the constant SMTP server to specify and default from address in parameters.

This assumes your internal SMTP server is open (allows relaying) from traffic on the LAN.

Code:
Public Sub SendEmailCDO(strTo As Variant, strCC As Variant, strSubject As Variant, strBody As Variant, Optional strAttachment As String = "", Optional strFrom As String = "SomeOne@example.com")
    
    'Send e-mail with CDO.  Avoid Outlook trust issues.  Can specify From or reply address instead of a no reply address.
    'Requires Reference to "Microsoft CDO for Windows 2000 Library" If not using late Binding... Converted  to use late binding
        
    Dim cdoMessage As Object 'CDO.Message
    Dim cdoConfig  As Object 'CDO.Configuration
    Dim strFiles() As String
    Dim lngFileCount As Long
    Dim i As Long
    
    Const conSMPTServer = "smtp@example.com"
    
    Set cdoMessage = CreateObject("CDO.Message")
    Set cdoConfig = CreateObject("CDO.Configuration")
    
    
    
    'cdoConfig.Fields(cdoSendUsingMethod).Value = cdoSendUsingPort
    cdoConfig.Fields("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing").Value[/URL] = 2 'cdoSendUsingPort
    
    'cdoConfig.Fields(cdoSMTPServer).Value = conSMPTServer
    cdoConfig.Fields("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver").Value[/URL] = conSMPTServer
    
    'cdoConfig.Fields(cdoSMTPServerPort).Value = 25
    cdoConfig.Fields("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport").Value[/URL] = 25
    
    cdoConfig.Fields.Update
    
    Set cdoMessage.Configuration = cdoConfig
    
    With cdoMessage
        .To = strTo
        .From = strFrom
        .Subject = strSubject
        .CC = strCC
        '.TextBody = "This is the body of the first plain text email with CDO."
        .HTMLBody = strBody
        
        If strAttachment <> "" Then
          strFiles = Split(strAttachment, ",")
          lngFileCount = UBound(strFiles)
          For i = 0 To lngFileCount Step 1
            .AddAttachment (Trim(strFiles(i)))
          Next i
        End If
        
        .Send
    End With
    
    Set cdoConfig = Nothing
    Set cdoMessage = Nothing
    
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top