I am not getting the delivery notification for the cdo email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nkanne
    New Member
    • Mar 2011
    • 1

    I am not getting the delivery notification for the cdo email

    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
    Code:
    <%
    
    		connstr = Application("conIntranetAdmin_ConnectionString")
    		set conn = server.CreateObject("ADODB.Connection")
    		set rs = server.CreateObject("ADODB.Recordset")
    		
    		set emailobj = createobject("CDO.Message")
    		emailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
    		'*** Name or IP of Remote SMTP Server)
    		emailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailrelay.company.net"
    		'*** Server port (typically 25) 
    		emailobj.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
    		'emailobj.Configuration.DSNOptions = cdoDSNSuccessFailOrDelay
    		'emailobj.DSNOptions = 14
    		emailobj.Configuration.Fields.Update
    	
    		emailobj.From = "agentuser@company.net"
    		emailobj.fields("urn:schemas:mailheader:disposition-notification-to") = "NatA@company.net" 'ToDo: Type a valid e-mail address.
    		emailobj.fields("urn:schemas:mailheader:return-receipt-to") = "NatA@company.net"  'ToDo: Type a valid e-mail address.
    		emailobj.DSNOptions = cdoDSNSuccessFailOrDelay
    		emailobj.DSNOptions = 14
    		emailobj.fields.update
    'response.Write "connstr:" & connstr & "<br>"
    
    		conn.Open connstr
    		
    		sql = "peoplesoftdb.dbo.aspGetNotificationList14DayContractor"
    		set rs = conn.Execute(sql)
    		msg14="test mail for 14 days"
    		do while not rs.EOF 
    			tmp = sendemail(rs("email"), rs("login"), "14 day notice", msg14 , emailobj)
    			
    			if tmp <> "Success" then
                    
                    errsub = "ERROR - " & subject14
                    errmsg = "error sending account expiration email - " & tmp
                	sendemail "NatA@company.net", rs("login"), errsub, errmsg, emailobj
                	'response.write tmp & "<br>"
    '            'else
    '            	'response.write tmp & "<br>"
    			end if
    'end of commend lines			
    		rs.MoveNext
    		loop
    		set emailobj = nothing
    
    
    function sendEmail(email, login, subject, msg, emailobj)
    
        on error resume next
    		emailobj.To = email
    		emailobj.subject = subject & login
    		emailobj.HTMLbody = msg
    							
    		emailobj.send					
    		if (err.number = 4) then
    			sendEmail = "Success"
    		elseif (err.number = 8) then
    			sendEmail = "Success"
    		elseif (err.number = 0) then
    			sendEmail = "Success"
    		else
    			sendEmail = "Failed - " & Err.description
    		end if
    		Response.write "email: " & email & " Delivery Status : " & err.Number & " " & sendEmail & "<BR>"
    		
    end function
    
    
    function sendEmailNew(email, login, subject, msg)
    
    
    		Const cdoSendUsingPickup = 1 
    		Const cdoSendUsingPort = 2 'Must use this to use Delivery Notification
    		Const cdoAnonymous = 0
    		Const cdoBasic = 1 ' clear text
    		Const cdoNTLM = 2 'NTLM
    		'Delivery Status Notifications
    		Const cdoDSNDefault = 0 'None
    		Const cdoDSNNever = 1 'None
    		Const cdoDSNFailure = 2 'Failure
    		Const cdoDSNSuccess = 4 'Success
    		Const cdoDSNDelay = 8 'Delay
    		Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay
    
    		'Send by using the port on an SMTP server.
    		Dim iMsg 
    		Dim iConf 
    		Dim Flds 
    		Dim strHTML
    		dim tmpVal
    
    		set imsg = createobject("cdo.message")
    		set iconf = createobject("cdo.configuration")
    
    		Set Flds = iConf.Fields
    		With Flds
    			.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    			.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailrelay.company.net" 'ToDo: Type a valid SMTP server name.
    			.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
    			.Update
    		End With
    
    		strHTML = "<HTML>"
    		strHTML = strHTML & "<HEAD>"
    		strHTML = strHTML & "<BODY>"
    		strHTML = strHTML & "<b> This is the test HTML message body</b></br>"
    		strHTML = strHTML & "<hr>"
    		strHTML = strHTML & "This another section of the message...</BR>"
    		strHTML = strHTML & "</BODY>"
    		strHTML = strHTML & "</HTML>"
    
    		With iMsg
    			Set .Configuration = iConf
    			.To = email 'ToDo: Type a valid e-mail address.
    			.From = "sql.agentuser@company.net" 'ToDo: Type a valid e-mail address.
    			.Subject = "This is a test CDOSYS message (Setting DSN options)"
    			.HTMLBody = strHTML
    			'.fields("urn:schemas:mailheader:disposition-notification-to") = "NatA@company.net" 'ToDo: Type a valid e-mail address.
    			.fields("urn:schemas:mailheader:return-receipt-to") = "NatA@company.net"  'ToDo: Type a valid e-mail address.
    			'.fields("urn:schemas:mailheader:disposition-notification-to") = "NatA@company.net" 'ToDo: Type a valid e-mail address.
    			
    			'Set DSN options.
    		'    Name                   Value       Description
    		'    cdoDSNDefault             0       No DSN commands are issued.
    		'    cdoDSNNever               1       No DSN commands are issued.
    		'    cdoDSNFailure             2       Return a DSN if delivery fails.
    		'    cdoDSNSuccess             4       Return a DSN if delivery succeeds.
    		'    cdoDSNDelay               8       Return a DSN if delivery is delayed.
    		'    cdoDSNSuccessFailOrDelay  14      Return a DSN if delivery succeeds, fails, or is delayed.
    
    			.DSNOptions = cdoDSNSuccessFailOrDelay
    			'.DSNOptions = cdoDSNFailure
    			.DSNOptions = 14
    			.fields.update
    			.Send
    		End With
    		
    		'for each field in iMsg.fields
    		'	Response.Write("<B>"&field.name&"</B: " & field.value & "<BR>")
    		'next
    				Response.write "<BR> <BR>" & "SendEmail New email: " & email & " Delivery Status : " & err.Number & "<BR>"
    		set imsg = Nothing
    		set iconf = Nothing
    		
    end function
    %>
Working...