I am new to programming as well as VB Script. I am trying to send multiple HMTL attachments via SMTP using CDO. I am able to get the html documents to attach, but what I am having problems with is looping through the code. I am tyring to group the html docs by location, when that location changes I want to start another email as well as a new set of attachments. Currently I have three html files I am trying to attach. The first email contains two attachments, but the second email contains all three of the attachments. I need it to break it down for the first email to have two attachments and the second email to have one attachment. I have included the code. Am I going about this the right way? Any help or suggestions would be appreciated. I am running on a Windows 2000 with Exchange 5.5.
' Send by connecting to port 25 of the SMTP server.
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim Filename
Dim Infile
Dim FSO
Dim I
Const cdoSendUsingPort = 2
Const ForReading = 1
set iMsg = CreateObject("CDO.Message"
set iConf = CreateObject("CDO.Configuration"
Set FSO = CreateObject("Scripting.FileSystemObject"
Set Infile = FSO.OpenTextFile("path to file",ForReading)
Set Flds = iConf.Fields
' Set the CDOSYS configuration fields to use port 25 on the SMTP server.
With Flds
.Item(" = cdoSendUsingPort
'ToDo: Enter name or IP address of remote SMTP server.
.Item(" = "IP address of smtp server"
.Item(" = 10
.Update
End With
' Build HTML for message body.
strHTML = "<HTML>"
strHTML = strHTML & "<HEAD>"
strHTML = strHTML & "<BODY>"
strHTML = strHTML & "<b> This is the test HTML message body</b></br>"
strHTML = strHTML & "</BODY>"
strHTML = strHTML & "</HTML>"
' Apply the settings to the message.
Dim LNum
Dim HNum
With iMsg
Set .Configuration = iConf
.To = "<anyone@anywhere.com>"
.From = "<someone@somewhere.com>"
.Subject = "Test Message"
.HTMLBody = strHTML
Lnum = Infile.Read(2) 'plant code
Do While Not Infile.AtEndOfStream
Select Case LNum
Case "00"
Msgbox "Plant " & LNum 'Confirming Line Number
Filename = Infile.ReadLine 'reads entire record
Set iBP = iMsg.AddAttachment("path to file" & Filename) 'add the attachment
Case "01"
Msgbox "Plant " & LNum
Filename = Infile.ReadLine
Set iBP = iMsg.AddAttachment("path to file" & Filename)
End Select
If NOT Infile.AtEndOfStream then
HNum = LNum
LNum = InFile.Read(2)
End if
If LNum <> HNum then
.Send
Msgbox "Mail Sent!"
End if
Loop
End With
' Clean up variables.
Infile.Close
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
Thanks.
teters
' Send by connecting to port 25 of the SMTP server.
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim Filename
Dim Infile
Dim FSO
Dim I
Const cdoSendUsingPort = 2
Const ForReading = 1
set iMsg = CreateObject("CDO.Message"
set iConf = CreateObject("CDO.Configuration"
Set FSO = CreateObject("Scripting.FileSystemObject"
Set Infile = FSO.OpenTextFile("path to file",ForReading)
Set Flds = iConf.Fields
' Set the CDOSYS configuration fields to use port 25 on the SMTP server.
With Flds
.Item(" = cdoSendUsingPort
'ToDo: Enter name or IP address of remote SMTP server.
.Item(" = "IP address of smtp server"
.Item(" = 10
.Update
End With
' Build HTML for message body.
strHTML = "<HTML>"
strHTML = strHTML & "<HEAD>"
strHTML = strHTML & "<BODY>"
strHTML = strHTML & "<b> This is the test HTML message body</b></br>"
strHTML = strHTML & "</BODY>"
strHTML = strHTML & "</HTML>"
' Apply the settings to the message.
Dim LNum
Dim HNum
With iMsg
Set .Configuration = iConf
.To = "<anyone@anywhere.com>"
.From = "<someone@somewhere.com>"
.Subject = "Test Message"
.HTMLBody = strHTML
Lnum = Infile.Read(2) 'plant code
Do While Not Infile.AtEndOfStream
Select Case LNum
Case "00"
Msgbox "Plant " & LNum 'Confirming Line Number
Filename = Infile.ReadLine 'reads entire record
Set iBP = iMsg.AddAttachment("path to file" & Filename) 'add the attachment
Case "01"
Msgbox "Plant " & LNum
Filename = Infile.ReadLine
Set iBP = iMsg.AddAttachment("path to file" & Filename)
End Select
If NOT Infile.AtEndOfStream then
HNum = LNum
LNum = InFile.Read(2)
End if
If LNum <> HNum then
.Send
Msgbox "Mail Sent!"
End if
Loop
End With
' Clean up variables.
Infile.Close
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
Thanks.
teters