Solved

send an email with attachment with CDONTS

Posted on 2000-05-09
12
296 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 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