[AccessD] SendObject Attachments

jwcolby jwcolby at colbyconsulting.com
Mon Dec 17 04:54:10 CST 2007


Any chance I can reference a specific lib so that I can get early binding
and intellisense to get me started using this thing?  IOW instead of

  Dim objCDO, objBP
  Set objCDO = CreateObject("CDO.Message")    ' Create the message object.

we have a Dim cdo as XXXX where xxxx is an actual object type.  Likewise for
objBP.

John W. Colby
Colby Consulting
www.ColbyConsulting.com 
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
max.wanadoo at gmail.com
Sent: Saturday, November 24, 2007 6:40 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] SendObject Attachments

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


--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list