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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Attachments using ASP

Status
Not open for further replies.

SmokeyJoe

Programmer
Nov 13, 2000
80
0
0
US
I have a MYSQL database of members, I want to be able to send members emails with attachments.

Using the following ASP code I can send emails without attachments but get error 800421a when I try an attachment.

I believe the problem is the attachment is on localhost and the server tries to find it on the server.

Data is selected/entered on the previous page and set into variables using "Request.form"

vAttachment contains the address of the file on the local computer; "C:\myfile\xxx.txt".

CODE:
Set oMSG = createobject("CDO.Message")
oMSG.To = veMailAddress
oMSG.From = vSender
oMSG.Subject = vSubject
oMSG.TextBody = veMailMessage
if vAttachment <> "" then
Att = " & vAttachment
oMSG.AddAttachment(Att)
end if
oMSG.Send()
set oMSG=nothing

I have tried several various ideas of " without success. What is the correct syntax to add an attachment using a file on the local computer?

Thanks for any help
smokeyjoe
 
change this Att=" & vAttachment
to this
Att=Server.mappath ("./" & vAttachment)
or this
Att=Server.mappath (vAttachment)
use response.write Att
to help get it right


DougP, MCP, A+
 
Thanks DougP
I tried the following got this error.

vAttachment = c:\alerts.txt

Att=Server.mappath ("./" & vAttachment) ' Line 32 of code
Server.MapPath() error 'ASP 0173 : 80004005'
Invalid Path Character
/SendEMail.asp, line 32

An invalid character was specified in the Path parameter for the MapPath method.
Same error if I use C:/alerts.txt

if I change line 32 of code to
Att=Server.mappath (vAttachment) ' Line 32 of code and use the same input strings
I get...
Server.MapPath() error 'ASP 0172 : 80004005'
Invalid Path
/SendEMail.asp, line 32
The Path parameter for the MapPath method must be a virtual path. A physical path was used.

Any ideas what the proper code should be?

smokeyjoe
 
give this a try if the file is located in the same folder as your page
Att="./" & vAttachment

DougP, MCP, A+
 
or how about just the file name
Att=vAttachment

DougP, MCP, A+
 
[1]
>vAttachment = c:\alerts.txt
[tt]vAttachment = [red]"[/red]c:\alerts.txt[red]"[/red][/tt]
[2]
If that's is a local file with the absolute path like shown, you don't any server.mappath or else; simply att=vattachment suffice.
 
Thanks guys but I get the message:


Response.write of Att = c:AnnResume2.doc

CDO.Message.1 error '80070003'
The system cannot find the path specified.

I think it is looking for the file on the server when it is really on the client side. However, I have tried using 127.0.0.1 and localhost to look at the client computer without success so I have the wrong syntax if that is what is needed.
smokeyjoe
 
Ah, thats the missing piece. You cannot access client-side files using server-side objects in ASP. At least not without some very interesting drive mapping code, windows authentication settings, and various other not-so-fun things.

 
Many thanks, guess I will have to look at another way.
smokey joe
 
How are you starting your script
<%@ Language=VBScript %>
OR
<script Language="VBScript">

DougP, MCP, A+
 
Thanks Doug, I did a cut and paste from one of my pages and I am using;


<%@ Language=VBScript %>

smokey joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top