troubleshooting Question

CDO Causes Server Crash on Second Email

Avatar of slamhound
slamhound asked on
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"">"
                        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


                        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"

                        Set oStream = oAttachment.GetDecodedContentStream
                        oStream.Type = adTypeText
                        oStream.WriteText sCSV
' This works the first time but crashes the second time

                        if err.number <> 0 then
                              ' LOG ERROR
                              LogPrecastError Request.ServerVariables("SCRIPT_NAME") & " (Send Email Error)"
                        end if

                        set oStream = Nothing
                        set oAttachment = Nothing
                        Set oNewMail = Nothing
                        set oConf = Nothing

                        On Error Goto 0
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros