slamhound
asked on
CDO Causes Server Crash on Second Email
I have inherited some code that crashes the server the second time an email is sent using CDO. I've inlcuded the relvant portions of the code below. How do I stop it crashing the server?
Dim oAttachment, oStream, sCSV
On Error Resume Next
sMsgBody = "<HTML>"
sMsgBody = sMsgBody & "<STYLE TYPE=""text/css"">"
sMsgBody = sMsgBody & " .stdFont { font-family: Verdana; font-size: x-small; }"
sMsgBody = sMsgBody & " .stdFontBold { font-family: Verdana; font-size: x-small; font-weight: bold; }"
sMsgBody = sMsgBody & " .stdFontHeading { font-family: Verdana; font-size: medium; font-weight: bold; }"
sMsgBody = sMsgBody & "</STYLE>"
sMsgBody = sMsgBody & "<BODY>"
sMsgBody = sMsgBody & "<P ALIGN=""CENTER"" CLASS=""stdFontHeading"">"
<snip>
sMsgBody = sMsgBody & GetTranshipmentHTMLByID(lT ranshipmen tID)
sMsgBody = sMsgBody & "<P CLASS=""stdFontBold""><FON T COLOR=""darkgreen"">A CSV file is attached to this email for importing into Excel</FONT></P>"
sMsgBody = sMsgBody & "</BODY></HTML>"
set oConf = Server.CreateObject("CDO.C onfigurati on")
Set oNewMail = Server.CreateObject("CDO.M essage")
oConf(cdoSendUsingMethod) = cdoSendUsingPort
oConf(cdoSMTPServer) = EMAIL_SERVER
oConf(cdoSMTPServerPort) = EMAIL_PORT
oConf.Fields.Update
set oNewMail.Configuration = oConf
' send to the dispatcher and CC to the distribution list
oNewMail.From = sDispatcherEmail
oNewMail.To = sDispatcherEmail
oNewMail.CC = EMAIL_CC
oNewMail.Subject = "Precast Transhipment - " & PrecastEntryTypeName(oForm .FormArgum ent("entry Type").Val ue)
oNewMail.HTMLBody = sMsgBody
sCSV = GetTranshipmentCSVByID(lTr anshipment ID)
set oAttachment = oNewMail.Attachments.Add
oAttachment.Fields.Item(cd oContentTy pe).Value = "text/plain; name=""transhipment.csv"""
oAttachment.Fields.Item(cd oContentDi sposition) .Value = "attachment; filename=""transhipment.cs v"""
oAttachment.Fields.Item(cd oContentTr ansferEnco ding).Valu e = "7bit"
oAttachment.Fields.Update
Set oStream = oAttachment.GetDecodedCont entStream
oStream.Type = adTypeText
oStream.WriteText sCSV
oStream.Flush
' This works the first time but crashes the second time
oNewMail.Send
if err.number <> 0 then
' LOG ERROR
LogPrecastError Request.ServerVariables("S CRIPT_NAME ") & " (Send Email Error)"
end if
oStream.Close
set oStream = Nothing
set oAttachment = Nothing
Set oNewMail = Nothing
set oConf = Nothing
On Error Goto 0
Dim oAttachment, oStream, sCSV
On Error Resume Next
sMsgBody = "<HTML>"
sMsgBody = sMsgBody & "<STYLE TYPE=""text/css"">"
sMsgBody = sMsgBody & " .stdFont { font-family: Verdana; font-size: x-small; }"
sMsgBody = sMsgBody & " .stdFontBold { font-family: Verdana; font-size: x-small; font-weight: bold; }"
sMsgBody = sMsgBody & " .stdFontHeading { font-family: Verdana; font-size: medium; font-weight: bold; }"
sMsgBody = sMsgBody & "</STYLE>"
sMsgBody = sMsgBody & "<BODY>"
sMsgBody = sMsgBody & "<P ALIGN=""CENTER"" CLASS=""stdFontHeading"">"
<snip>
sMsgBody = sMsgBody & GetTranshipmentHTMLByID(lT
sMsgBody = sMsgBody & "<P CLASS=""stdFontBold""><FON
sMsgBody = sMsgBody & "</BODY></HTML>"
set oConf = Server.CreateObject("CDO.C
Set oNewMail = Server.CreateObject("CDO.M
oConf(cdoSendUsingMethod) = cdoSendUsingPort
oConf(cdoSMTPServer) = EMAIL_SERVER
oConf(cdoSMTPServerPort) = EMAIL_PORT
oConf.Fields.Update
set oNewMail.Configuration = oConf
' send to the dispatcher and CC to the distribution list
oNewMail.From = sDispatcherEmail
oNewMail.To = sDispatcherEmail
oNewMail.CC = EMAIL_CC
oNewMail.Subject = "Precast Transhipment - " & PrecastEntryTypeName(oForm
oNewMail.HTMLBody = sMsgBody
sCSV = GetTranshipmentCSVByID(lTr
set oAttachment = oNewMail.Attachments.Add
oAttachment.Fields.Item(cd
oAttachment.Fields.Item(cd
oAttachment.Fields.Item(cd
oAttachment.Fields.Update
Set oStream = oAttachment.GetDecodedCont
oStream.Type = adTypeText
oStream.WriteText sCSV
oStream.Flush
' This works the first time but crashes the second time
oNewMail.Send
if err.number <> 0 then
' LOG ERROR
LogPrecastError Request.ServerVariables("S
end if
oStream.Close
set oStream = Nothing
set oAttachment = Nothing
Set oNewMail = Nothing
set oConf = Nothing
On Error Goto 0
ASKER
No error. Just the server crashing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Think I've lost the client so no need to complete this question.
Stilgar.