Solved

New to CDO: Sending client attachments with ASP using CDO

Posted on 2004-08-20
8
369 Views
Last Modified: 2008-02-01
Hi,

We are a small office with a network running a Cobalt Qube 3 server (LINUX).
This box has Chilisoft ASP, and a couple of components: Chil!Mail, Chili!Upload.
My .asp apps work great now. Using CDONTS.

We are now in the process of upgrading our complete network. My apps will need to move over to our new server: Windows 2003 Standard O/S.
I have read many posts, and know that I have to save the file to the server before attaching to the email.

I am therefore new to CDO.
If I have a standard HTML form with an Input box for the client to select a file, how do I save this to our server and then attach to my email. ?


I have the following code which works for sending the email....I just need to add code to SAVE to file and then ATTACH


+++++++++++++++++


<html>
<body>

<%

response.write "Email sent....Check your in-box !"

strTo = "ME@ME.COM"
strFrom = "YOU@YOU.COM"
strSubject = "TEST EMAIL"
strBody = "The content of email"
strIP = "XX.XX.XX.XX" ' Put your ip here

Set objCDOMail = Server.CreateObject("CDO.Message")
   
' Set the properties of the object
 objCDOMail.From = StrFrom
 objCDOMail.To = strTo
 objCDOMail.Subject = strSubject
 objCDOMail.TextBody = strBody
 objCDOMail.Configuration.Fields("cdo/configuration/smtpserver") = strIP
 objCDOMail.Configuration.Fields("cdo/configuration/sendusing") = 2
 objCDOMail.Configuration.Fields.Update


' Some of the more useful ones I've included samples of here:
' objCDOMail.Cc = "mailto:thirt@cinci.rr.com;ahirt@cinci.rr.com"
' objCDOMail.Bcc = "Khirt@cinci.rr.com"
' objCDOMail.Importance = 1
' objCDOMail.AttachFile "d:\websites\als\about.html", "filename.txt"

' Send the message!
objCDOMail.Send

' Set the object to nothing because it immediately becomes
' invalid after calling the Send method + it clears it out of the Server's Memory.
Set objCDOMail = Nothing

   

%>

</body>
</html>

+++++++++++++++++

Appreciate your soonest help

David
0
Comment
Question by:scene
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 2

Accepted Solution

by:
MGrassman earned 125 total points
ID: 11851041
I don't know if this is what you are looking for but this is how you save a file in asp.

You will also need write permissions of the folder so I usually use a temp folder

set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile(server.MapPath("temp/name_of_file_to_save.txt"), True) 'True means to overwrite
filetxt.WriteLine("First line of text")
filetxt.Write("No line break after command")
filetxt.WriteLine("Last Line of text")
filetxt.Close

Hope this helps
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11851110
Use chiliupload to upload the file, and then use CDO to send the mail with the attachment.  You seem to know how to do that?  What is your question?
0
 

Author Comment

by:scene
ID: 11851124
Thanks,

The files are usually MS Word docs..does this matter using CreateTextFile ?

Also, for some reason, my code does not like the METHOD 'objCDOMail.AttachFile'

Object doesn't support this property or method: 'AttachFile'
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 31

Expert Comment

by:alorentz
ID: 11851157
>>does this matter using CreateTextFile ?

Yes, FSO does not create.doc files...that is why you need to use an upload component.

See here for syntax:

http://www.paulsadowski.com/WSH/cdo.htm
0
 

Author Comment

by:scene
ID: 11851164
alorentz,

Sorry, should have been clearer.

Lets forget about CDONTS & Chili!Upload.
Just think Windows 2003 Server & CDO.

HTML Page, using form upload.
Filename carried to asp page.

How do I save their selected doc to file, and then how can I test if it exists and if so, attach it to my email ?

Thanks again

David
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11851222
Again, you need SOME KIND OF UPLOAD COMPONENT.  Unless you want to write it all yourself, buy why do that when you can get a free component.

Try ASPSIMPLEUPLOAD http://www.aquanet.co.il/vip/download/dialers, or ASPUPLOAD.

And, I gave you code for CDO.
0
 
LVL 2

Expert Comment

by:MGrassman
ID: 11851770
No that won't I thought you were creating the file

With the chiliUpload object you created use this

objChili.SaveToFile("/upload/" & filename)

you may need the full server path to the upload folder \root\mysite\uploadfolder

The folder has to be created and given write permissions.


0
 
LVL 11

Expert Comment

by:mouatts
ID: 11853936
As alorentz has said using a component is probably the easiest way but you can do it in plain ASP if you want by using ADO.Stream to read the file from request.binaryread and then save it. If you want the actual code let me know.

Steve
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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