[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Object doesn't support this property or method: 'AttachFile'  using CDO email object

Posted on 2006-05-28
15
Medium Priority
?
6,025 Views
Last Modified: 2009-03-17
I am trying to send an attachment along with my email using CDO but I am getting the error message:
Object doesn't support this property or method: 'AttachFile'
Using this:

Set objCDOMail = Server.CreateObject("CDO.Message")
objCDOMail.From    = strFrom
      objCDOMail.To      = strTo
      objCDOMail.Subject = strSubject
      objCDOMail.TextBody = strBody
      objCDOMail.Cc        = "info@purelifecoach.com"
      objCDOMail.AttachFile =attachment
      'objCDOMail.AddAttachment = attachment
      objCDOMail.Send
      Set objCDOMail = Nothing
      Response.Write "Message sent to " & strTo & "!<br><br><br>"

Any ideas on why this might be al works fine (emails are sent) if I do not include that line:objCDOMail.AttachFile =attachment
0
Comment
Question by:rabbits2
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 25

Expert Comment

by:kevp75
ID: 16779424
it should be:
objCDOMail.AddAttachment = attachment
0
 

Author Comment

by:rabbits2
ID: 16779565
Tried this and get error message:

Object doesn't support this property or method: 'AddAttachment'

Any other ideas?
0
 
LVL 9

Expert Comment

by:blandyuk
ID: 16779625
The ".Attachfile" method is associated with the "CDONTS" object, not the "CDO.Message" object.

With regards to the above, it should be ".AddAttachment". See the below for details:

http://www.w3schools.com/asp/asp_send_email.asp
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 25

Expert Comment

by:kevp75
ID: 16779626
you may need to set the CDO configuration in order to send an attachment, but the right coding for it is .AddAttachment
also please check that you are actually giving a value to your variable attachment.

If you can do this:
if attachment = "" OR ISNULL(attachment) then
  response.write("There is nothing to attach")
else
  response.write("There is an attachement")
end if

to just above Set objCDOMail = Server.CreateObject....  and then run the script it will show you if you are setting a value to attachment

check these links:

CDOSYS
http://www.w3schools.com/asp/asp_send_email.asp
http://www.codeproject.com/asp/cdoex.asp
http://quadcomm.com/tips/sendCDOSYSmail.txt


CDONTS:
http://www.4guysfromrolla.com/webtech/112298-1.shtml
http://authors.aspalliance.com/wiseasp/aboutemail.asp

please note that CDONTS was discontinued in windows 2003, and CDOSYS is now used.
0
 

Author Comment

by:rabbits2
ID: 16779697
I definity have a value in the variable attachment, that I've checked
Still getting the error:

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'AddAttachment'

You say I amy have to set the CDO configuration in order to send an attachment.  How do I do this?
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16779710
you say the value is getting set, but if you do the check I suggested, you may find that it is not.  Please do the check I suggested.

the second link I posted will show you how to set the configuration
0
 

Author Comment

by:rabbits2
ID: 16779731
I did run your test this is what I get:
There is an attachement

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'attachment.AddAttachment'


I have also used your link and added in the configuration lines like this:
if attachment = "" OR ISNULL(attachment) then
  response.write("There is nothing to attach")
else
  response.write("There is an attachement")
end if
Set objCDOMail = Server.CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

Dim Flds
Set Flds = iConf.Fields
Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Flds( _
 "http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") _
  = "c:\inetpub\mailroot\pickup"
Flds.Update
Set objCDOMail.Configuration = iConf
objCDOMail.From    = "info@caukus.com"
      objCDOMail.To      = strTo
      objCDOMail.Subject = strSubject
      objCDOMail.TextBody = strBody
      objCDOMail.Cc        = "info@purelifecoach.com"
      'myMail.AddAttachment "c:\mydocuments\test.txt"
      objCDOMail.AddAttachment = attachment
      objCDOMail.Send
      Set objCDOMail = Nothing
      Response.Write "Message sent to " & strTo & "!<br><br><br>"


Anything else you can think of, would love to solve this, thanks.
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16779739
the code is right.

the only other thing that I can say is try changing:
objCDOMail.AddAttachment = attachment

to:
objCDOMail.AddAttachment = "c:\mydocuments\test.txt"

or, try it with the =
0
 

Author Comment

by:rabbits2
ID: 16779763
Not sure what you mean by:
or, try it with the =

Have tried using:
objCDOMail.AddAttachment = "c:\mydocuments\test.txt"
Inserting a correct path to an existing file on the server but still getting this same error: Object doesn't support this property or method: 'AddAttachment' .

Is this a common problem or is something feaking out for me? Not quite sure what steps to take next.
0
 
LVL 25

Accepted Solution

by:
kevp75 earned 1200 total points
ID: 16779765
i'm sorry, I meant without the =

so it would be:
objCDOMail.AddAttachment "c:\mydocuments\test.txt"
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16779773
here's another link if you need some light reading  :)
http://www.interlacken.com/winnt/tips/tipshow.aspx?tip=46

looks like with the AddAttachment method of CDO there is no need for the =
0
 

Author Comment

by:rabbits2
ID: 16779842
Yes! Just found that out!   It works if I use:

objCDOMail.AddAttachment "D:\webs\hushclothing.co.uk\html\images3\one.gif "

and so does:

objCDOMail.AddAttachment attachment

All that over one =

Thanks for your help
0
 
LVL 25

Expert Comment

by:kevp75
ID: 16779868
:)  anytime

thanks for the grade.
0
 

Expert Comment

by:DeonM
ID: 23905485
I think the only reason the formatting ain't happening is due to the incorrect data value types.
I have attached the current SQL query im using.

The field that needs trimming is in table alias "a" with the column name "Intro_Date".
The field that needs formatting to currency is in the table alias "a" as well with column name "Price".

Both fields are of type varcher in SQL.

Hope this ain't to confusing.

Thanks
SELECT a.*, b.Dealer_Name, c.make as vmake, c.Variant as vmodel, c.Intro_Date FROM Used_Stock a, Dealer b, Meads c 
                                    WHERE a.Company_Number = b.ID 
                                    AND a.Mead_Code = c.MCode 
                                    AND c.Make = @var_make

Open in new window

0
 

Expert Comment

by:DeonM
ID: 23905500
Ooops, added comment to wrong thread :P
Please remove any of my comments from this thread
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question