Solved

New to CDO: Sending client attachments with ASP using CDO

Posted on 2004-08-20
8
362 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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 information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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