Solved

send an email with attachment with CDONTS

Posted on 2000-05-09
12
295 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

939 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now