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!

send mail with multiple attachments

Status
Not open for further replies.

patrick118

Technical User
Jan 14, 2004
315
NL
I have the following script

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "test@test.com"
objMessage.To = "test@test.com"
objMessage.AddAttachment "c:\test.txt"
objMessage.TextBody = "This is some sample message text."

'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
(" = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
(" = "Mailserver"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
(" = 25

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send
============================================================
Now i don't want to get test.txt as an attachment but i would like to get all the text files in the directory so i tried *.txt but doesn't work.

Is there a way of getting all the txt files in a directory?

Thanks for the help.
 
Well...This is how I send multiple attachments in ASP. You'll have to change some stuff (Request objects) but I think you'll get the gist of it.

If you want to send all the .txt files in a directory, I'm thinking you could use FSO (file system object) to loop through the name of each .txt file in the directory, and do an objNewMail.AttachFile() on them. There may be a better way to do it, but that is what pops into my mind first.

HTH.

Code:
Dim objNewMail
Set objNewMail = CreateObject("CDONTS.NewMail")

objNewMail.From = "somewhere@else.com"
objNewMail.To = "somewhere@else.com
'objNewMail.Cc = 
'objNewMail.Bcc = 
'objNewMail.Bcc = Request.Form("txtBcc")
objNewMail.Subject = "subject"

objNewMail.BodyFormat = 0
objNewMail.MailFormat = 0
objNewMail.Body = "Body.."

if not isnull(Request.Form("txtAttach1")) and Request.Form("txtAttach1")<>"" then
	objNewMail.AttachFile(Server.MapPath(Request.Form("txtAttach1")))
end if
if Not isnull(Request.Form("txtAttach2")) and Request.Form("txtAttach2")<>"" then
	objNewMail.AttachFile(Server.MapPath(Request.Form("txtAttach2")))
end if
if not isnull(Request.Form("txtAttach3")) and Request.Form("txtAttach3")<>"" then
	objNewMail.AttachFile(Server.MapPath(Request.Form("txtAttach3")))
end if
if not isnull(Request.Form("txtAttach4")) and Request.Form("txtAttach4")<>"" then
	objNewMail.AttachFile(Server.MapPath(Request.Form("txtAttach4")))
end if
objNewMail.Send

Set objNewMail = Nothing

All hail the INTERWEB!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top