Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attach file to email using CDONTS

Status
Not open for further replies.

lamore

Technical User
Nov 19, 2000
11
US
Hi All,
I hope someone can help me out. I have a form that is submitted online that is emailed using CDONTS. That part works great, now I need to be able to let user attach a file from their computer to the email. Obviolously I don't know ahead of time what the file name and location is so I need to add a browse button and browse their system and attach. Does anyone know an easy way to do this??

Thanks,
Lennny
 
What would the code in the email sending page look like?
What would I put in place of the question marks????

Below is my code:
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.To = "dblacks1@ford.com"
objMail.bcc = "lamore@ford.com"
objMail.From = "mof@ford.com"
objMail.Subject = "M.O.F. for Toolroom"
objMail.BodyFormat = 0
objMail.MailFormat = 0
objMail.AttachFile("???????????????")
objMail.Body = Recordset1.Fields.Item("requestedby").Value & " " & strMessage
objMail.Send
Set objMail = Nothing


Thanks,
Lenny
 
form filed=[.....to whatever they browse to....]
eg.
objMail.AttachFile("d:\images\pic.gif")

> need more info?
:: don't click HERE ::
 
When I put the browse button in and browse to the file on my harddrive it doesn't work, it doesn't send anything. I must be doing something wrong....
 
does your form field get populated?
try something in this direction
form field = "C:\file path"
.............
varMyIMAGE = Request.Form("name_of_the_FORM_field")
objMail.AttachFile("varMYImage")
...let me know if ur still having truble...perhaps I can make a smple file or something...anyhow
All the best!

> need more info?
:: don't click HERE ::
 
I did what you said and I get this message:

error '80004005'

Unspecified error

/Inetpub/materialorder/TMPcvgbwnub4s.asp, line 56
here is the code:
<%@LANGUAGE=&quot;VBSCRIPT&quot; CODEPAGE=&quot;1252&quot;%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body>
<p>Send email with attachment:</p>
<form action=&quot;&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot; name=&quot;form1&quot;>
<table width=&quot;75%&quot; border=&quot;0&quot;>
<tr>
<td>To: </td>
<td><input name=&quot;emailto&quot; type=&quot;text&quot; id=&quot;emailto2&quot;></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>From: </td>
<td><input name=&quot;emailfrom&quot; type=&quot;text&quot; id=&quot;emailfrom2&quot;></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Message:</td>
<td><textarea name=&quot;emailbody&quot; id=&quot;emailbody&quot;></textarea></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>AttachFile:</td>
<td><input name=&quot;emailfile&quot; type=&quot;file&quot; id=&quot;emailfile&quot;></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;></td>
<td>&nbsp;</td>
</tr>
</table>
</form>
<p>&nbsp;<%

Dim varMyIMAGE
Set objMail = Server.CreateObject(&quot;CDONTS.NewMail&quot;)
objMail.To = &quot;lamore@ford.com&quot;
objMail.bcc = &quot;lamore@ford.com&quot;
objMail.From = &quot;mof@ford.com&quot;
objMail.Subject = &quot;Material Order Form&quot;
objMail.BodyFormat = 0
objMail.MailFormat = 0
objMail.Body = &quot;test&quot;
varMyIMAGE = Request.Form(&quot;emailfile&quot;)
objMail.AttachFile(&quot;varMYImage&quot;)
objMail.Send
Set objMail = Nothing

Response.write(&quot;<i>Mail was Sent</i><p>&quot;)




%>
</p>
</body>
</html>


Getting pretty frustrated...
Thanks,
Lenny
 
I did exactly as the Microsoft website directed and it didn't work. It works as long as I don't attach a file to it. So if I just put in email addresses it sends email...if I attach a file it goes back to the default.asp page which is the begining page...... Now I'm thinking that there is a component missing on the server, any more suggestions????? Getting desperate...

Thanks,
Lenny
 
u should/need to have an ASPUpload or some other...upload component.
they way it works (this is all based on theory from Micro)
u 1st. upload a file to some loaction on your server eg.

&quot;/emil/attachements/110503/image.gif&quot;

and then user ServerMappath or a full path to pull the images
objMail.AttachFile(&quot;???????????????&quot;)
would be
objMail.AttachFile(&quot;
honestly, I have not tested my upload component so I have no code to pass along. try to test it and see if u can attach an image that is already on your server...if that works than your CDONTS are working ok and u need to find Upload component. ASPUpload is free....
All the best!



> need more info?
:: don't click HERE ::
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top