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

Send e-mail with attachments?

Status
Not open for further replies.

adamsoderqvist

Programmer
Sep 8, 2001
136
SE
Hallo every one.

I want to send e-mail with VBScript, and use this code:

***************** C O D E ********************

'Begin e-mail sequence!
Dim strFrom, strTo, strSubject, strMessage, objMail

'Get senders info
strFrom = "xx@xxx.com"

'Get recipients info
strTo = "xx@xxx.com"

'Subject
strSubject = "X"

'Message body
strMessage = "My msg

Set objMail = Server.CreateObject("CDONTS.NewMail")

objMail.From = strFrom
objMail.To = strTo
objMail.Subject = strSubject
objMail.Body = strMessage
objMail.AttachFile = "C:\XX.doc"
objMail.Send

Set objMail = Nothing

***************** E N D C O D E ********************

Now, the code works fine when sending just the mail, but I can't get it to work with the attachment-code-line (see above).

So my Q is easy: how do I send e-mail with one (and more) attached files?

/Adam
 
Code:
dim objMail
set objMail = server.createobject("cdonts.newMail")

	with objMail
		.From = fromName
		.To =  rs("email")
		.Subject =  "Data Accuracy Report - " & cbr
		.Body =  strOut
		[blue]call .AttachFile (fileName,  , 1)[/blue]
		.bodyFormat = 0		'HTML'
		[blue].mailFormat = 0		'MIME [/blue]Format'
		.send
	end with

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
No, I can't get it to work. I get an error saying: "The page cannot be displayed" - not even an ASP-err code..

Any suggestions..?
 
OK, I tried it, but it doesnt work. Again, the simple mail sending works fine, but when I try to send an attachment it fails, saying it's an "HTTP 500 - Internal server error", could this be due to that the server doesn't support the attachment feature?
 
you are not able to see the error because friendly HTTP error messages are on.

in ur browser (IE) Tool > Internet Options > Advanced, there will be a Show Friendly HTTP error messages. disable it. now u shold be able to see the correct ASP error...

Known is handfull, Unknown is worldfull
 
I'm using CDONTS and the command I have for attaching a file is as follows

Code:
iMSG.AddAttachment ("c:\path_to_file")

This works fine for me...



Pat Russell
 
OK, y'all. I'm making progress..

I changed the friendly HTTP error messages, and it turned out that the system couldn't find the path specified. This applies when I attach from "C:\...", BUT when I attach from the internet, using an URL-path, like
" it works and my e-mails are attached!

The error code I recieve (when I attach from my computer) is:

"CDO.Message.1 error '80070003'

The system cannot find the path specified."

What's causing this? Anyone got an idea..?

/Happy new year
 
Hey again,
Could it be that the server that hosts the ASP pages (with the e-mail code) doesn't relate to "my" hard drive?

I tried this:

objMail.AddAttachment Request.ServerVariables("Remote_addr") & "\" & "C:\MyDocs\MyDoc.txt", though I got a syntax error. But in theory, the IP-address should be the key, or am I wrong..?

When I print the code above using response.write, I get my IP-adress + the path on my computer, i.e.: "212.08.222.17\C:\MyDocs\Mydoc.txt"

/Adam
 
try this instead...

objMail.AddAttachment server.mappath("../myFile.jpg")

or move the attachment to the C: drive (no folder) and try

objMail.addAttachment ("C:/myFile.jpg")



Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
You might also want to check the share name of the drive you are trying to pull the file from. When using a network address I'm pretty sure you need to use the share name rather than drive letter (unless that is the share name).

"212.08.222.17\C:\MyDocs\Mydoc.txt" is probably not a valid address over the network but
"212.08.222.17\C\MyDocs\Mydoc.txt" might be (I removed the colon).




Pat Russell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top