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!

Sending HTML attachments via SMTP using CDO

Status
Not open for further replies.

teters

Technical User
Oct 4, 2002
16
0
0
US
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 = &quot;<HTML>&quot;
strHTML = strHTML & &quot;<HEAD>&quot;
strHTML = strHTML & &quot;<BODY>&quot;
strHTML = strHTML & &quot;<b> This is the test HTML message body</b></br>&quot;
strHTML = strHTML & &quot;</BODY>&quot;
strHTML = strHTML & &quot;</HTML>&quot;

' Apply the settings to the message.

Dim LNum
Dim HNum

With iMsg
Set .Configuration = iConf
.To = &quot;<anyone@anywhere.com>&quot;
.From = &quot;<someone@somewhere.com>&quot;
.Subject = &quot;Test Message&quot;
.HTMLBody = strHTML

Lnum = Infile.Read(2) 'plant code
Do While Not Infile.AtEndOfStream
Select Case LNum
Case &quot;00&quot;
Msgbox &quot;Plant &quot; & LNum 'Confirming Line Number
Filename = Infile.ReadLine 'reads entire record
Set iBP = iMsg.AddAttachment(&quot;path to file&quot; & Filename) 'add the attachment
Case &quot;01&quot;
Msgbox &quot;Plant &quot; & LNum
Filename = Infile.ReadLine
Set iBP = iMsg.AddAttachment(&quot;path to file&quot; & Filename)
End Select
If NOT Infile.AtEndOfStream then
HNum = LNum
LNum = InFile.Read(2)
End if
If LNum <> HNum then
.Send
Msgbox &quot;Mail Sent!&quot;
End if
Loop

End With

' Clean up variables.

Infile.Close
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing



Thanks.

teters
 
i think u have an algorithm problem in the with..end with loop
not really a coding problem.

if you could write the contents of the with.endwith in pseudocode,
us ppl who arent completely familiar with cdo can problem think up a better algorithm for you.




===============
Security Forums
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top