[AccessD] SendObject Attachments

max.wanadoo at gmail.com max.wanadoo at gmail.com
Sat Nov 24 05:40:10 CST 2007


Hi Rocky,
This should get you started with CDO.  Put your own parameters in - fairly
obvious where.
Max

Function RockyCDOTest()
  On Error GoTo errhandler
  Const conErr1 As String = "The server rejected one or more recipient
addresses. The server response was: 550 "
  Const conErr2 As String = "The server rejected one or more recipient
addresses. The server response was: 501 bad address syntax: <"
  Const ConErrX As String = "The transport failed to connect to the server"
  Const cdoReferenceTypeName = 1
  Dim strUserName As String, strPwd As String, strSMTPServer  As String,
strErr As String
  Dim objCDO, objBP
  Set objCDO = CreateObject("CDO.Message")    ' Create the message object.
  'Set objCDO = server.CreateObject("CDO.Message") ' alternative for
exchange I believe! Not tested
  objCDO.mimeformatted = True

  ' Sender/Email Contents/Details
  objCDO.from = "Rocky<rocky at rockydomain.com>"
  objCDO.To = "somebody at gmail.com"
  objCDO.cc = "person1 at domain.com;person2 at domain.com"
  objCDO.bcc = "person3 at domain.com"
  objCDO.Subject = "Testing 123"

  'body can be a string, or read from a file and can be text or html (Don't
use both)
  objCDO.HTMLBody = fFileContents("C:\body.html") ' or "C:\body.txt" '
create a test file

  ' Attachments
  objCDO.addattachment "C:\Att1.txt" ' create a test file
  objCDO.addattachment "C:\Att2.jpg" ' create a test file

  ' User SMTP login details
  strSMTPServer = "mail.rockydomain.org" ' send via this domain - can be IP
Address (sometimes this is smtp.mydomain.org)
  strUserName = "rocky" ' your user login name
  strPwd = "itsrockyletmein" ' your user login password

  ' SMTP Configuration Details
 
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configura
tion/sendusing") = 2
 
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configura
tion/smtpserver") = strSMTPServer
 
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configura
tion/smtpauthenticate") = 1
 
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configura
tion/sendusername") = strUserName
 
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configura
tion/sendpassword") = strPwd
 
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configura
tion/smtpserverport") = 25 'normally 25  but can be anything, try 587, or
465 or check with your ISP.
 
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configura
tion/smtpusessl") = False
 
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configura
tion/smtpconnectiontimeout") = 60 ' before timing out
  objCDO.Configuration.Fields.Update    ' Update configuration
  'MsgBox objCDO.GetStream.ReadText  ' Use to show the message.
  objCDO.Send  ' Send the message.
exithere:
  Exit Function
errhandler:
  strErr = "pfEmailByCDO - Send Errors " & Err.Description
  If InStr(strErr, ConErrX) > 0 Then
    strErr = strErr & " No Email Sent"
  End If
  MsgBox strErr
  GoTo exithere
End Function

Private Function fFileContents(strFilePath As String) As String
  ' Set a Reference for FileSystemObjects in Office 11.
  'These constants are defined to make the code more readable
  Const ForReading = 1, ForWriting = 2, ForAppending = 8
  Dim fso, f
  Set fso = CreateObject("Scripting.FileSystemObject")
  'Open the file for reading
  Set f = fso.OpenTextFile(strFilePath, ForReading)
  'The ReadAll method reads the entire file
  fFileContents = f.ReadAll
  f.Close    'Close the file
  Set f = Nothing
  Set fso = Nothing
End Function 


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Rocky Smolin at
Beach Access Software
Sent: Friday, November 23, 2007 6:13 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] SendObject Attachments

Thanks, Max.  Working the first solution at the moment.   If that works I'll
stop the clock, and go there to see if it works at their site.  

What's CDO?

Rocky





More information about the AccessD mailing list