Solved

send an email with attachment with CDONTS

Posted on 2000-05-09
12
298 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
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/…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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