Link to home
Start Free TrialLog in
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
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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Think I've lost the client so no need to complete this question.