troubleshooting Question

CDO Causes Server Crash on Second Email

Avatar of slamhound
slamhound asked on
ASP
4 Comments1 Solution345 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
_Stilgar_

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004