I have used the below method brought to my attention by Tom back in August and it works great.  To send to multiple recipients, just past strTo a string with multiple addresses separated by semicolons.
 
HTH,
Toby
 
****************Archived Email************************************
----- Original Message -----
From: Tom Oakes
Sent: Tuesday, August 09, 2005 10:05 AM
Subject: RE: [AccessDevelopers] E-mail with spreadsheet attachment

I have a client that doesn't have Outlook accounts available on the application server, so we resorted to using the CDO library to send email.  You can essentially do everything you can with Outlook - except edit the email prior to sending.  The CDO library does not raise any type of security warning.
 
My routine looks like this:
(the bolded parts are system option functions - you can replace these with literal strings)
 
'***** code start *****'
Public Function SendCDOMail(strTo As String, strSubject As String, strBody As String, strAttach As String, blnHTML As Boolean) As Boolean
On Error GoTo Failure
 
        Dim objMessage As CDO.Message
        Dim objConfig As CDO.Configuration
        Dim objFields As Variant
       
        Const cboSendUsingPort As Integer = 2
       
        Set objConfig = New CDO.Configuration
        Set objMessage = New CDO.Message
        Set objFields = objConfig.Fields
       
        With objFields
            .Item("
http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
            .Item("
http://schemas.microsoft.com/cdo/configuration/smtpserver") = GetSMTPServer()  '<-- valid SMTP server
            .Item("
http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
            .Item("
http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Update
        End With
       
        With objMessage
            Set .Configuration = objConfig
            .TO = strTo
            .From = GetNTUSER & "@" & GetMailDomain()  '<-- automatically uses current user as "From"
            .Subject = strSubject
            If blnHTML = True Then
                .HTMLBody = strBody
            Else
                .TextBody = strBody
            End If
            If strAttach <> "" Then .AddAttachment (strAttach)
            .Send
        End With
      
       Set objMessage = Nothing
       Set objFields = Nothing
       Set objConfig = Nothing
     
      SendCDOMail = True
     
EXITROUTINE:
    Exit Function
Failure:
    SendCDOMail = False
    MsgBox Err & " " & Err.Description
    Resume EXITROUTINE
End Function

'***** code end *****'
**************End Archived Email**************************************
----- Original Message -----
Sent: Monday, November 28, 2005 8:14 PM
Subject: [AccessDevelopers] Sending Email via Code

Is there a way to send email via code without invoking outlook?

I have an application that may run on a machine with outlook and it may run on a machine with groupwise. I need something more generic than the Create Outlook Object process.
 
I am needing more than the SendObject also because I am exporting two queries into one one file to create two excel sheets in a workbook.

Thanks.


May God bless you beyond your imagination!
Lonnie Johnson
ProDev
, Professional Development of MS Access Databases
Visit me at ==> http://www.prodev.us




 


Yahoo! Music Unlimited - Access over 1 million songs. Try it free.


Please zip all files prior to uploading to Files section.




YAHOO! GROUPS LINKS




Reply via email to