Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > ASP CDO
|
ASP CDO As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP CDO section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2003, 09:59 PM
Registered User
 
Join Date: Dec 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need some help> converting CDONTS email code to JM

evening,

I could use some help with converting an order confirmation page using CDONTS to Jmail. The app is CharonCart 3. If you could be specific as to what exactly I need to change I would appreciate it.

Ualtered original related code is below. Thanks very much.

R


<%
'This is the part where we send out emails.
'There's a 101 different ways of doing it. I'm outlining 2 here.
'The first method uses CDOSYS. It's probably the best way of doing things but it can be flaky.
'Look at the line below, I've commented out the CDOSYS code. But you can use it if you want.
'SendEmail 'This line calls the function below and sends the email

'The second mthod is using CDONTS. Basically, the setting are in an XML file
'in the XML folder of this site. You can easily change the content of the email.
SendCdoEmail

'Start the functions
function SendEmail
'on error resume next 'This code will only work on a Win2k server.
Dim iMsg,iConf,Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields

EmailPage="http://localhost/CartV3/Email.asp?OrderID=" & OrderID & "&CustomerID=" & CustomerID
'Response.Write(EmailPage)
'Response.End()

With Flds
' assume constants are defined within script file
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
.Update
End With

With iMsg
Set .Configuration = iConf
.To = CustomerRS("CustomerEmail")
.From = "[email protected]"
.Subject = "Charon Cart Order"
'.TextBody = "test"
.CreateMHTMLBody cstr(EmailPage)
.Send
End With
end function

function SendCdoEmail

Set objXML = Server.CreateObject("Microsoft.XMLDOM")
dim strBody
objXML.load(Server.MapPath("xml/orders_email.xml"))
set objNodeXML=objXML.documentElement
strFrom=objNodeXML.selectSingleNode("from").Text
strSubject=objNodeXML.selectSingleNode("subject"). Text
strBody=objNodeXML.selectSingleNode("body").Text
Set objXML = Nothing
'Response.Write mailbody(strBody)
'response.End()
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
objCDOMail.From = strFrom
objCDOMail.To = CustomerRS("CustomerEmail")
objCDOMail.Subject = strSubject
objCDOMail.Body = mailbody(strBody)
objCDOMail.MailFormat=0
objCDOMail.BodyFormat=0
objCDOMail.Send
Set objCDOMail = Nothing
end function

'This function will replace the tokens in the XML file with contents of recordset
function mailbody(c)
tmpStr=c
tmpStr=replace(tmpStr,"#OrderID#",Session("OrderID "))
tmpStr=replace(tmpStr,"#OrderDetails#",OrderDetail s)
tmpStr=replace(tmpStr,"#OrderSummary#",OrderSummar y)
'Look at this next bit. In the XML file, the tokens are replaced by content from the recordset.
'So, if you've got #FirstName# in the XML file
'it will be replaced by FirstName content of recordset. Neat, eh?
for each fld in CustomerRS.Fields
if CustomerRS(fld.Name) & "" <> "" then
tmpStr=replace(tmpStr,"#" & fld.Name & "#",CustomerRS(fld.Name))
end if
next
mailbody=tmpStr
end function

function OrderDetails
tmpStr=""
while not CustomerOrderRS.eof
tmpStr=tmpStr & "ProductID - " & CustomerOrderRS("ProductID") & "<br>"
tmpStr=tmpStr & "Product - " & CustomerOrderRS("ProductName") & "<br>"
tmpStr=tmpStr & "Size - " & CustomerOrderRS("ProductSize") & "<br>"
tmpStr=tmpStr & "Colour - " & CustomerOrderRS("Colour") & "<br>"
tmpStr=tmpStr & "Quantity - " & CustomerOrderRS("Quantity") & "<br>"
tmpStr=tmpStr & "Unit Price - £" & formatnumber(CustomerOrderRS("UnitPrice"),2) & "<br>"
tmpStr=tmpStr & "==============" & "<br>" & "<br>"
CustomerOrderRS.movenext
wend
CustomerOrderRS.requery

OrderDetails=tmpStr
end function

function OrderSummary
tmpStr=""
tmpStr=tmpStr & "Subtotal - £" & formatnumber(OrdersRS("SubTotal"),2) & "<br>"
tmpStr=tmpStr & "Shipping - £" & formatnumber(OrdersRS("Freight"),2) & "<br>"
tmpStr=tmpStr & "Sales Tax - £" & formatnumber(OrdersRS("SalesTax"),2) & "<br>"
tmpStr=tmpStr & "Grandtotal - £" & formatnumber(OrdersRS("GrandTotal"),2) & "<br>" & "<br>"

OrderSummary=tmpStr
end function
%>

Don't know if you need this page for the above, orders_email.xml:

<?xml version="1.0"?>
<root>
<from>[email protected]</from>
<to>customer</to>
<cc>[email protected]</cc>
<subject>Order confirmation from Products website</subject>
<body><![CDATA[
<p>Order Confirmed with Thanks</p>
<p>Your Order No. is #OrderID#<p>
<p>Your order will be sent to:<br>
#FirstName# #LastName#<br>
#DeliveryAddress1# #DeliveryAddress2#<br>
#ShipCity# #ShipRegion# #ShipPostalCode#
</p>
<p>
#OrderDetails#
</p>
<p>
#OrderSummary#
</p>
]]></body>
</root>


 
Old March 16th, 2004, 01:15 AM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

below is a script I used for mailing that i called in a function see if you can modify it to work for you.

Set JMail = Server.CreateObject("JMail.SMTPMail")
' Set jmail = Server.CreateObject("JMail.Message")
    JMail.ServerAddress = gSMTP
    JMail.Sender = gCompanyEmail

    JMail.Priority = 3
    JMail.AddHeader "Originating-IP", Request.ServerVariables("REMOTE_ADDR")
    JMail.Logging = True

    jmail.AddRecipient cEmail
    if not cBCC="" then
        if instr(cBCC,",")>0 then
            aBCC=split(cBCC,",")
        else
            aBCC=split(cBCC,";")
        end if
        for iii=0 to ubound(aBCC)
            JMail.AddRecipientBCC aBCC(iii)
' response.Write aBCC(iii)&"<br>"
        next
    end if

    jmail.Subject = cSubject
    if lHTML then
        jmail.HTMLBody=cBody
    end if
    jmail.Body =cBody
    jmail.Execute
    set JMail=nothing

I would appreciate if you can help me with a CDO problem . I can't get it to send the HTML part. I have four different htm files that get sent out based on the customer responce


<%
function sendemail(cEmail,cName,cSubject,cBody,cBCC,lHTML)
On Error Resume Next

  if gEmailComponent="CDO" then
    Dim objCDO
    Dim iConf
    Dim Flds

    Const cdoSendUsingPort = 2

    Set objCDO = Server.CreateObject("CDO.Message")
    Set iConf = Server.CreateObject("CDO.Configuration")
'cdoSendUsingPort
    Set Flds = iConf.Fields
    With Flds
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail-fwd"
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 40
            .Update
    End With

    Set objCDO.Configuration = iConf

    'objCDO.From = gCompanyEmail
    objCDO.To = cEmail
    objCDO.BCC = cBCC
    'objCDO.Value("Reply-To") = gCompanyEmail
    objCDO.From = gCompanyEmail
    objCDO.Subject = cSubject
    'objCDO.importance = 1

    'Set body format for lHTML
            if lHTML then
             objCDO.HTMLBody = cBody
            else
             objCDO.TextBody = cBody
            end if
    objCDO.Send
   'set objCDO = closed
   'Set iConf = closed
   'Set Flds = closed
'Response.redirect "confirmation.html"
' Any existing page can be used for the response redirect method
'END IF

    Set objCDO = nothing
    Set iConf = Nothing
    Set Flds = Nothing
end if
Error=Err.description

sendemail=Err=0

end Function

%>







Similar Threads
Thread Thread Starter Forum Replies Last Post
Please Help: CDONTs - Form to Email problem nancy Classic ASP Basics 18 October 29th, 2004 05:35 PM
Email using Frontpage and CDONTS levinho Classic ASP Databases 0 November 17th, 2003 04:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.