Solved

send an email with attachment with CDONTS

Posted on 2000-05-09
12
297 Views
Last Modified: 2012-05-04
set oMail = CreateObject("CDONTS.NewMail")
With oMail
   .From = "Me@anywhere.com"
   .To = "Someone@RightHere.com"
   .Subject = "You owe me $5000"
   .attachFile "c:\a.txt","a"
   .Send
End With


in above example, it works. but the problem is the attachfile is the file that in the webserver not the file that the client wants to attach.

how do i send mail with attachment using CDONTS object to attach files that the one the user wants? just like hotmail or yahoo!
 
0
Comment
Question by:hdrik
  • 3
  • 2
  • 2
  • +4
12 Comments
 
LVL 4

Accepted Solution

by:
mberumen earned 200 total points
ID: 2795540
I am not familiar with uploading files for attachment but more than likely you will have to use a file upload component to your server. once uploaded you can attach it as part of the email.

try aspupload at

http://www.aspupload.com/

The reason for this is that the mail process is running in the server, not on the client's browser..
0
 

Expert Comment

by:meganhall
ID: 2795626
I have done this before, but as mberuman says, the client must upload the file first. i did this using the Persits aspUpload component. This is available at http://www.persits.com

The user then uploads the file to a directory that you specify.

Set Upload = server.CreateObject("Persits.Upload.1")The directory can be anything eg. c:\Blob as long as Blob folder exists on the server.
You can use the FileSystemObject to create folders strPath = "c:\upload"
This uploads the file to a specified directory:
Count = Upload.Save (strPath)

Get the file path and name
strFile = File.Path
Then use the Attachfile method
    .attachFile strFile,"a"

I hope this helps
   



0
 
LVL 2

Expert Comment

by:indu_ma
ID: 2795632
upto my knowledge it takes the file from the client machine only
 i use a file field which has a text box and a browse button . when i click the browse button open dialog box comes ,where i choose the file from my hard disk and say submit

in serverside
i use CDONTS to send mail
set oMail = CreateObject("CDONTS.NewMail")
With oMail
   .From = "Me@anywhere.com"
   .To = "Someone@RightHere.com"
   .Subject = "You owe me $5000"
   .attachFile request.form("filename")
   .Send
End With

and works fine for me
i am also able to send more than one attachment but i use a slightly additional code for that
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 

Expert Comment

by:meganhall
ID: 2795646
indu_ma, does this code (Request.Form("filename") attach the entire file with the contents or just the file name?
0
 
LVL 8

Expert Comment

by:xabi
ID: 2795683
You must use a component to upload the file to the server:

You can do it ussign a lot of free/pay components around like:

http://www.aspupload.com/ 
http://www.softartisans.com/ 
http://www.dougdean.com/EZsiteUpLoadSite.htm 

If you can't install any component you can use this free pure asp upload routines:

http://www.pstruh.cz/help/ScptUtl/library.htm 

and you can find more here:

http://www.aspin.com/home/components/file/upload 

xabi
0
 
LVL 2

Expert Comment

by:indu_ma
ID: 2795706
The cdonts component actually creates a outlook express file isn't . if u open the mail u can see both the attachments
0
 
LVL 3

Expert Comment

by:Hencah
ID: 2795709
Yes... you must upload the file to the server and you can use free component such as aspSmartUpload (www.aspsmart.com) or why don't you try coding yourself to upload files, please read this article:

www.asptoday.com/articles/20000316.htm

good luck
0
 

Author Comment

by:hdrik
ID: 2795786
what happened when we already upload the files, but the user cancel to submit the mail.
then we have a lot of junk in our server
0
 

Author Comment

by:hdrik
ID: 2795787
what happened when we already upload the files, but the user cancel to submit the mail.
then we have a lot of junk in our server.


0
 

Author Comment

by:hdrik
ID: 2795794
what happened when we already upload the files, but the user cancel to submit the mail.
then we have a lot of junk in our server.


0
 
LVL 4

Expert Comment

by:ruperts
ID: 2796098
I can see two problems:
Firstly what happens when the user uploads a file and then leaves the site or loses his connection.
Secondly, what happen if two users both upload a file with same file name at the same time.

I think the way to solve the problems is to save the files as a sequential number. And then store the details in a database.

i.e.
userID
fileID
filename

Then use the session end event to delete all files for that user so that nothing gets left behind
0
 
LVL 3

Expert Comment

by:Hencah
ID: 2799086
You just upload the file when the user submit it! And no junk files in your server. It's easy, when the user has already determine their filename to be attached (at this point he hasn't uploaded the files yet, he just tell file's name). After he submit then you really upload the file to the server, get its name and pass it to CDONTS attach file prop , then send it! After successfull you can delete the uploaded file.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

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 …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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