ASP
--
Questions
--
Followers
Top Experts
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
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Whats the error you're getting?
Stilgar.
Stilgar.
No error. Just the server crashing.
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Think I've lost the client so no need to complete this question.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
ASP
--
Questions
--
Followers
Top Experts
Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.