By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,659 Members | 1,678 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,659 IT Pros & Developers. It's quick & easy.

I am not getting the delivery notification for the cdo email

P: 1
I need help with receiving 'failure delivery notification', when email address is incorrect.


In the database, there are emails which are invalid. My asp programs should send me an email saying that delivery failed for that email address.
My script seems to work, if the email address is valid, but it does not give me a notification, if delivery fails or email address is incorrect.
I tried two functions to see if it works, but was not successfull.
Spent couple of hours on the issue, but could not figure out the problem, Any help is appreciated.
Thanks
Nat
Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3.         connstr = Application("conIntranetAdmin_ConnectionString")
  4.         set conn = server.CreateObject("ADODB.Connection")
  5.         set rs = server.CreateObject("ADODB.Recordset")
  6.  
  7.         set emailobj = createobject("CDO.Message")
  8.         emailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
  9.         '*** Name or IP of Remote SMTP Server)
  10.         emailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailrelay.company.net"
  11.         '*** Server port (typically 25) 
  12.         emailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
  13.         'emailobj.Configuration.DSNOptions = cdoDSNSuccessFailOrDelay
  14.         'emailobj.DSNOptions = 14
  15.         emailobj.Configuration.Fields.Update
  16.  
  17.         emailobj.From = "agentuser@company.net"
  18.         emailobj.fields("urn:schemas:mailheader:disposition-notification-to") = "NatA@company.net" 'ToDo: Type a valid e-mail address.
  19.         emailobj.fields("urn:schemas:mailheader:return-receipt-to") = "NatA@company.net"  'ToDo: Type a valid e-mail address.
  20.         emailobj.DSNOptions = cdoDSNSuccessFailOrDelay
  21.         emailobj.DSNOptions = 14
  22.         emailobj.fields.update
  23. 'response.Write "connstr:" & connstr & "<br>"
  24.  
  25.         conn.Open connstr
  26.  
  27.         sql = "peoplesoftdb.dbo.aspGetNotificationList14DayContractor"
  28.         set rs = conn.Execute(sql)
  29.         msg14="test mail for 14 days"
  30.         do while not rs.EOF 
  31.             tmp = sendemail(rs("email"), rs("login"), "14 day notice", msg14 , emailobj)
  32.  
  33.             if tmp <> "Success" then
  34.  
  35.                 errsub = "ERROR - " & subject14
  36.                 errmsg = "error sending account expiration email - " & tmp
  37.                 sendemail "NatA@company.net", rs("login"), errsub, errmsg, emailobj
  38.                 'response.write tmp & "<br>"
  39. '            'else
  40. '                'response.write tmp & "<br>"
  41.             end if
  42. 'end of commend lines            
  43.         rs.MoveNext
  44.         loop
  45.         set emailobj = nothing
  46.  
  47.  
  48. function sendEmail(email, login, subject, msg, emailobj)
  49.  
  50.     on error resume next
  51.         emailobj.To = email
  52.         emailobj.subject = subject & login
  53.         emailobj.HTMLbody = msg
  54.  
  55.         emailobj.send                    
  56.         if (err.number = 4) then
  57.             sendEmail = "Success"
  58.         elseif (err.number = 8) then
  59.             sendEmail = "Success"
  60.         elseif (err.number = 0) then
  61.             sendEmail = "Success"
  62.         else
  63.             sendEmail = "Failed - " & Err.description
  64.         end if
  65.         Response.write "email: " & email & " Delivery Status : " & err.Number & " " & sendEmail & "<BR>"
  66.  
  67. end function
  68.  
  69.  
  70. function sendEmailNew(email, login, subject, msg)
  71.  
  72.  
  73.         Const cdoSendUsingPickup = 1 
  74.         Const cdoSendUsingPort = 2 'Must use this to use Delivery Notification
  75.         Const cdoAnonymous = 0
  76.         Const cdoBasic = 1 ' clear text
  77.         Const cdoNTLM = 2 'NTLM
  78.         'Delivery Status Notifications
  79.         Const cdoDSNDefault = 0 'None
  80.         Const cdoDSNNever = 1 'None
  81.         Const cdoDSNFailure = 2 'Failure
  82.         Const cdoDSNSuccess = 4 'Success
  83.         Const cdoDSNDelay = 8 'Delay
  84.         Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay
  85.  
  86.         'Send by using the port on an SMTP server.
  87.         Dim iMsg 
  88.         Dim iConf 
  89.         Dim Flds 
  90.         Dim strHTML
  91.         dim tmpVal
  92.  
  93.         set imsg = createobject("cdo.message")
  94.         set iconf = createobject("cdo.configuration")
  95.  
  96.         Set Flds = iConf.Fields
  97.         With Flds
  98.             .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  99.             .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailrelay.company.net" 'ToDo: Type a valid SMTP server name.
  100.             .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
  101.             .Update
  102.         End With
  103.  
  104.         strHTML = "<HTML>"
  105.         strHTML = strHTML & "<HEAD>"
  106.         strHTML = strHTML & "<BODY>"
  107.         strHTML = strHTML & "<b> This is the test HTML message body</b></br>"
  108.         strHTML = strHTML & "<hr>"
  109.         strHTML = strHTML & "This another section of the message...</BR>"
  110.         strHTML = strHTML & "</BODY>"
  111.         strHTML = strHTML & "</HTML>"
  112.  
  113.         With iMsg
  114.             Set .Configuration = iConf
  115.             .To = email 'ToDo: Type a valid e-mail address.
  116.             .From = "sql.agentuser@company.net" 'ToDo: Type a valid e-mail address.
  117.             .Subject = "This is a test CDOSYS message (Setting DSN options)"
  118.             .HTMLBody = strHTML
  119.             '.fields("urn:schemas:mailheader:disposition-notification-to") = "NatA@company.net" 'ToDo: Type a valid e-mail address.
  120.             .fields("urn:schemas:mailheader:return-receipt-to") = "NatA@company.net"  'ToDo: Type a valid e-mail address.
  121.             '.fields("urn:schemas:mailheader:disposition-notification-to") = "NatA@company.net" 'ToDo: Type a valid e-mail address.
  122.  
  123.             'Set DSN options.
  124.         '    Name                   Value       Description
  125.         '    cdoDSNDefault             0       No DSN commands are issued.
  126.         '    cdoDSNNever               1       No DSN commands are issued.
  127.         '    cdoDSNFailure             2       Return a DSN if delivery fails.
  128.         '    cdoDSNSuccess             4       Return a DSN if delivery succeeds.
  129.         '    cdoDSNDelay               8       Return a DSN if delivery is delayed.
  130.         '    cdoDSNSuccessFailOrDelay  14      Return a DSN if delivery succeeds, fails, or is delayed.
  131.  
  132.             .DSNOptions = cdoDSNSuccessFailOrDelay
  133.             '.DSNOptions = cdoDSNFailure
  134.             .DSNOptions = 14
  135.             .fields.update
  136.             .Send
  137.         End With
  138.  
  139.         'for each field in iMsg.fields
  140.         '    Response.Write("<B>"&field.name&"</B: " & field.value & "<BR>")
  141.         'next
  142.                 Response.write "<BR> <BR>" & "SendEmail New email: " & email & " Delivery Status : " & err.Number & "<BR>"
  143.         set imsg = Nothing
  144.         set iconf = Nothing
  145.  
  146. end function
  147. %>
  148.  
Mar 18 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.