Solved

send an email with attachment with CDONTS

Posted on 2000-05-09
12
293 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

11 Experts available now in Live!

Get 1:1 Help Now