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
Solved

New to CDO: Sending client attachments with ASP using CDO

Posted on 2004-08-20
8
363 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Use a variable for Class Name in Classic ASP 4 60
Select2 jquery help 9 94
Question about ASP Including Files 6 61
ASP Button to clear text 4 61
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…
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/…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 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