Avatar of slamhound
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(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
ASP

Avatar of undefined
Last Comment
slamhound
Avatar of _Stilgar_
_Stilgar_
Flag of Israel image

Whats the error you're getting?

Stilgar.
Avatar of slamhound
slamhound

ASKER

No error. Just the server crashing.
ASKER CERTIFIED SOLUTION
Avatar of _Stilgar_
_Stilgar_
Flag of Israel image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of slamhound
slamhound

ASKER

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

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.

82K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo