Link to home
Create AccountLog in
ASP

ASP

--

Questions

--

Followers

Top Experts

Avatar of slamhound
slamhound

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(lTranshipmentID)
                        sMsgBody = sMsgBody & "<P CLASS=""stdFontBold""><FONT 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.Configuration")

                        Set oNewMail = Server.CreateObject("CDO.Message")

                        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.FormArgument("entryType").Value)
                        oNewMail.HTMLBody = sMsgBody

                        sCSV = GetTranshipmentCSVByID(lTranshipmentID)

                        set oAttachment = oNewMail.Attachments.Add

                        oAttachment.Fields.Item(cdoContentType).Value = "text/plain; name=""transhipment.csv"""
                        oAttachment.Fields.Item(cdoContentDisposition).Value = "attachment; filename=""transhipment.csv"""
                        oAttachment.Fields.Item(cdoContentTransferEncoding).Value = "7bit"
                        
                        oAttachment.Fields.Update

                        Set oStream = oAttachment.GetDecodedContentStream
                        
                        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("SCRIPT_NAME") & " (Send Email Error)"
                        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.


Avatar of _Stilgar__Stilgar_🇮🇱

Whats the error you're getting?

Stilgar.

Avatar of slamhoundslamhound

ASKER

No error. Just the server crashing.

ASKER CERTIFIED SOLUTION
Avatar of _Stilgar__Stilgar_🇮🇱

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Think I've lost the client so no need to complete this question.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

ASP

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.