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

        objMessage.Send
leawassonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hc0904pcdCommented:
try this after objMessage.Text = eMsgString

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

0
hc0904pcdCommented:
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?
0
hc0904pcdCommented:
When it breaks, what is the error msg?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

jarwCommented:
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("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your.smtp.server"
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
mail.Configuration.Fields.Update()
 
mail.Subject = "Test Email"
mail.From = "yourname@somewhere.com"
mail.To = "anybody@somewhereelse.com"
mail.TextBody = "Hello World!"
 
mail.AddAttachment Server.MapPath("text.txt")
 
mail.Send()
 
Set mail = Nothing

Open in new window

0
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"
objMail.Send
Set objMail = Nothing

Thank  you again very much for you suggestions.
0
Computer101Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.