How do you send email attachments through an ASP page? [Print this FAQ]
Answer:
The CDONTS mail object can be used to send email attachments - it contains a method named AttachFile. The file you wish to attach must exist on the Web server (or be accessible on a remote machine by the IUSR_MachineName account) and the IUSR_MachineName must have Read permission on the file you wish to attach. Furthermore, you must know the file's physical path.
Below is a sample script (written by Rob Taylor) that sends an email attachment:
<% Option Explicit
Dim objMail Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = "friend@somewhere.com" objMail.Subject = "A message TO you" objMail.AttachFile("d:\images\pic.gif") objMail.To = "someone@someplace.com" objMail.Body = "This is the body of the Message" objMail.Send
Response.write("Mail was Sent")
'You should always do this with CDONTS. set objMail = nothing %>
If you attempt to attach a file that does not exist you will receive an Unspecified Error error message...
FAQ posted by Scott Mitchell at
9/24/2000 1:14:13 AM to the
Email category.
This FAQ has been viewed 111,649 times.
Do you have a FAQ you'd like to suggest?
Suggestions? Comments? If so, send it in!
Also, if you'd like to be a FAQ Admin (creating/editing FAQs),
let me know! If you are looking for other FAQs, be
sure to check out the 4Guys
FAQ and Commonly Asked Messageboard Questions!