Sending Mail attachment with VBScript

I am trying to attach a file when I send an email.  The email sends fine unless I add the attachment line, then it breaks.  All of the examples I've seen require a hard path except the line I use below with Server.MapPath.  This doesn't seem to work.  Please tell me what I'm doing wrong here.  The file is located in the directory that I'm running this asp from.

Set objSession = CreateObject("CDONTS.Session")
        objSession.LogonSMTP fromName, fromEmail
            'objSession.LogonSMTP fromname, fromemail
        Set objOutbox = objSession.Outbox
        Set objMessage = objOutbox.Messages.Add
        objMessage.Subject = esubject
        objMessage.Text = eMsgString
        objMessage.AddAttachment (Server.MapPath("text.txt"))
        'objMessage.Importance = CdoHigh
        if recip1= "true" then
            objMessage.Recipients.Add "recip1",etoaddr, cdoTo
        end if
        if recip2= "true" then
            objMessage.Recipients.Add "recip2",etoaddr2, cdoTo
        end if

Who is Participating?
Computer101Connect With a Mentor Commented:
PAQed with points refunded (500)

EE Admin
try this after objMessage.Text = eMsgString

strPath = Server.MapPath(".")
if attachment1 <> "" then objMessage.AddAttachment strPath & "\" & "attachment_filename"

Perhaps also test it with a word file.
I"m not a hundred per cent sure how a txt attachment will be treated.
Have you set the email to html, or text?
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

When it breaks, what is the error msg?
Do you have to use CDONTS or can you use CDOSYS? An example with CDOSYS is given below. It might be interesting to see if it fails the same way.
Set mail = CreateObject("CDO.Message")
' Configure to use an external mail server (2), supply its domain name or IP
' address (your.smtp.server), and tell it which port to use (usally 25).
mail.Configuration.Fields.Item("") = 2
mail.Configuration.Fields.Item("") = "your.smtp.server"
mail.Configuration.Fields.Item("") = 25 
mail.Subject = "Test Email"
mail.From = ""
mail.To = ""
mail.TextBody = "Hello World!"
mail.AddAttachment Server.MapPath("text.txt")
Set mail = Nothing

Open in new window

leawassonAuthor Commented:
Sorry for the slow response.  I was taken off this project for a few weeks and haven't had a chance to test the solutions you offered.  I tried all of the suggestions and nothing seemed to work.  I ended up using the following solution (switching to CDONTS.Newmail).

Dim physicalPath
physicalPath = Server.MapPath(".")
Dim fullPath
fullPath = physicalPath & "\my.pdf"            
Set objMail = CreateObject("CDONTS.Newmail")
objMail.From = fromEmail
objMail.To = etoaddr3
objMail.Subject = "Requested PDF"
objMail.Body = "you email body"
objMail.AttachFile fullPath, "Your PDF"
Set objMail = Nothing

Thank  you again very much for you suggestions.
All Courses

From novice to tech pro — start learning today.