cdo email with attachments (1 Viewer)

CharlesWh

Registered User.
Local time
Today, 22:14
Joined
Jan 19, 2006
Messages
36
I'm trying to modify the following code to allow attachements but keeps erroring "object doesnt support this propery or method" when I can see thatothers are using the same?

Code:
Private Sub cmdEmailProductSpecs_Click()
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

Set objmessage = CreateObject("CDO.Message")
Dim strUser As String
strUserName = Forms.FrmSplashScreen.txtUserName
Dim strReplyAddress As String
strReplyAddress = DLookup("EmailAddress", "TblDbUsers", "DbUserID = Forms!FrmSplashscreen!txtDbUserID")
Dim strSignature As String
strSignature = DLookup("EmailSignature", "TblDbUsers", "DbUserID = Forms!FrmSplashscreen!txtDbUserID")

objmessage.Subject = "Test"
objmessage.From = strReplyAddress
objmessage.To = "test@emailaddress.co.uk"
objmessage.Bcc = DLookup("EmailAddress", "TblDbUsers", "DbUserID = Forms!FrmSplashscreen!txtDbUserID")
objmessage.TextBody = "Test With Attachments"


'==This section obtains user variables from TblDbUsers & the message text.
Dim strSMTPserver As String
strSMTPserver = DLookup("smtpMailGateway", "TblDbUsers", "DbUserID = Forms!FrmSplashscreen!txtDbUserID")
Dim strUserID As String
strUserID = DLookup("smtpUserName", "TblDbUsers", "DbUserID = Forms!FrmSplashscreen!txtDbUserID")
Dim strUserPassword As String
strUserPassword = DLookup("smtpPassword", "TblDbUsers", "DbUserID = Forms!FrmSplashscreen!txtDbUserID")

'==This section provides the configuration information for the remote SMTP server.

objmessage.Configuration.fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objmessage.Configuration.fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPserver

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objmessage.Configuration.fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server
objmessage.Configuration.fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = strUserID

'Your password on the SMTP server
objmessage.Configuration.fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strUserPassword

'Server port (typically 25)
objmessage.Configuration.fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
objmessage.Configuration.fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objmessage.Configuration.fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objmessage.Configuration.fields.Update

'==End remote SMTP server configuration section==
objmessage.AddAttachment = ("C:\test.txt")

objmessage.send
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 23:14
Joined
Sep 7, 2009
Messages
1,819
What line is it highlighting when the code breaks?
 

CharlesWh

Registered User.
Local time
Today, 22:14
Joined
Jan 19, 2006
Messages
36
It's the following line:

objmessage.AddAttachment = ("C:\test.txt")
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 23:14
Joined
Sep 7, 2009
Messages
1,819
Have you dim'd objmessage as an Object?
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 23:14
Joined
Sep 7, 2009
Messages
1,819
Right at the start when you're declaring variables:
Code:
Dim objmessage as Object
 

CharlesWh

Registered User.
Local time
Today, 22:14
Joined
Jan 19, 2006
Messages
36
I think thats already done with the line

Set objmessage = CreateObject("CDO.Message")
 

CharlesWh

Registered User.
Local time
Today, 22:14
Joined
Jan 19, 2006
Messages
36
Also, email sends fine until I try to add the line with an attachment?
 

CharlesWh

Registered User.
Local time
Today, 22:14
Joined
Jan 19, 2006
Messages
36
the solution was to remove the =

this one works

objmessage.AddAttachment ("file://c:\test.txt")
 

JamesMcS

Keyboard-Chair Interface
Local time
Today, 23:14
Joined
Sep 7, 2009
Messages
1,819
That's what I was just going to say ;)

Glad it worked out! I'll remember that for next time
 

Users who are viewing this thread

Top Bottom