cdosys: Bounced Emails

Hello All,

I am using CDOSYS in my Email Marketing Web Application. Given below is the code that i use to send an email.. and it works, I am not able to detect if the file has bounced back. I am working on the Delivery Report and this is my first step towards it. I know there are lot of components out there that can manage all this for me. but i believe it is possible within the features offered by CDOSYS. The following link seems explaining it.

http://support.microsoft.com/?scid=kb;en-us;302839&spid=6384&sid=67

The code i used.

    Function SendTestMails(ByVal strHTML As String, ByVal strToEmailID As String) As Boolean

        Dim dtMember As DataTable
        Dim strFromMailId, strSMTPserver, strSMTPusername, strSMTPpassword, strSMTPport As String

        Try
            dtMember = pi_obj_Member.GetMembers(2)
        Catch ex As Exception
            System.Diagnostics.Debug.WriteLine(ex.Message)
        End Try

        If dtMember.Rows.Count > 0 Then
            strFromMailId = "me@company.com"
            strSMTPserver = "NNN.NN.NN.NN"
            strSMTPusername = "MyUserName"
            strSMTPpassword = "MyPassword"
            strSMTPport = "25"

            Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
            Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

            Const cdoAnonymous = 0 'Do not authenticate
            Const cdoBasic = 1 'basic (clear-text) authentication
            Const cdoNTLM = 2 'NTLM

            Dim objMessage As Object
            objMessage = CreateObject("CDO.Message")
            objMessage.Subject = "This is a test message"
            objMessage.From = strFromMailId
            objMessage.To = strToEmailID
            objMessage.HTMLBody = CStr("" & strHTML)

            '==This section provides the configuration information for the remote SMTP server.

            objMessage.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

            'Name or IP of Remote SMTP Server
            objMessage.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPserver

            'Type of authentication, NONE, Basic (Base64 encoded), NTLM
            objMessage.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

            'Your UserID on the SMTP server
            objMessage.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendusername") = strSMTPusername

            'Your password on the SMTP server
            objMessage.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strSMTPpassword

            'Server port (typically 25)
            objMessage.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = strSMTPport '25

            'Use SSL for the connection (False or True)
            objMessage.Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

            objMessage.Configuration.fields("urn:schemas:mailheader:disposition-notification-to") = "me@company.com"
            objMessage.Configuration.fields("urn:schemas:mailheader:return-receipt-to") = "me@company.com"
            objMessage.Configuration.Fields.Update()

            '==End remote SMTP server configuration section==
            Try
                objMessage.Send()
            Catch ex As Exception
                System.Diagnostics.Debug.WriteLine(ex.Message)
            End Try

            objMessage = Nothing
        End If

    End Function
asifthakurAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryFrancisLondCommented:
The above code will alert you if it hasn't managed to send to the specific e-mail address because of an issue such as it cannot find the remote SMTP server (at the company you are trying to send to).

However, to trap the bounce backs (Which are being sent to me@company.com you need to connect to this mailbox and monitor the e-mails coming through. As a bounce back doesn't usualyl occur instantly, and different mail servers are configured to keep trying for different periods of time, it is not unusual to wait around 72 hours before a boucne back occurs.

I assume the address where the bounce back occurs (me@company.com) is a service mailbox (not your account or an account that is expected to receive e-mail). IF this is the case, jsut write a simple service that checks the e-mails in this inbox and use some testing to see if this is a bounce back e-mail and work out for what e-mail address it has bounced back from. You will probably need to use some pattern matching for this.

As this is an e-mail marketing application, I am assuming you are storing the tracking status into a database of some sort. If this is the case, when you discover a bounce back has occurred just update the trcking database as you require it to be updated.

I am actually in the process of developing a very similar system on top of an existing eMarketing application I developed with .Net 2.0.

I hope that helps.

Gary Francis
Software Developer
*** URL removed by humeniuk PE ***
SammyCommented:
Just before this line objMessage.Configuration.Fields.Update()
add
ObjMessage.DSNOptions = cdoDSNSuccessFailOrDelay

HTH
asifthakurAuthor Commented:
Thanks a lot Mr Gary but right now i am blank about which way to proceed. As you said..  

" However, to trap the bounce backs (Which are being sent to me@company.com you need to connect to this mailbox and monitor the e-mails coming through. "

"jsut write a simple service that checks the e-mails in this inbox and use some testing to see if this is a bounce back e-mail and work out for what e-mail address it has bounced back from."

As far as i could understand, if i set the return path of an outgoing message, i will be able to recieve a bounced message. And as you said, i need to pattern match the recieved account i can do that. the problem is how to set the return path for the outgoing message. Any online example or guideline.

Thanks a lot.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

GaryFrancisLondCommented:
sammy1971 has almost got it right, instead of his line: ObjMessage.DSNOptions = cdoDSNSuccessFailOrDelay

You should put the following:

ObjMessage.DSNOptions = cdoDSNFailure

and further up in your code where you declare your constants you should have the following decalred:

Const cdoDSNFailure = 2 'Delivery Status Notification on failure

Regards,

Gary Francis
Software Developer
*** URL removed by humeniuk PE ***
GaryFrancisLondCommented:
Sorrey, I forgot to mention why you should do that. The reason you use DSNFailure isntead of DSNSuccessFailOrDelay is because you do not want to receive an e-mail back if you receive a success as this is a given if you do not receive a bounce back.

Adding success and delay checks in which increase the complecxity of the pattern matching you are going to have to do.

Regards,

Gary Francis
Software Developer
*** URL removed by humeniuk PE ***
asifthakurAuthor Commented:
Thanks Mr. Sammy but i have already tried it many times.. as explained in this article.

http://support.microsoft.com/?scid=kb;en-us;302839&spid=6384&sid=67

but the only result that i get out here is 550 along with a complete error message in case of a bad email address and 452 in case of over quota. this is when i read my exception. is there a better way to cover up such errors.

Thanks a lot,
GaryFrancisLondCommented:
What do you meany by "cover up such errors"?

Do you mean contineu the processing of the application in case of when of these errors? If this is the case, I woudl suggest the try{}catch{} block is the best (and onyl to my knowledge) method to accomplish this.

In terms of receivng the other errors (bounce backs) with the above code that sammy and I have provided you shoudl receive the bounce back messages in the me@company.com mailbox - like I have said it can take around 72 hours to receive some bounce backs depdning on yours and their mail servers.

Regards,

Gary Francis
Software Developer
*** URL removed by humeniuk PE ***
asifthakurAuthor Commented:
Yes this is exactly the point.. i want to continue the processing of the application even when there is an exception. I call this function in a loop while sending an email to a large number of people in my address book and for each one of them.. i fill the details and send. if there is an exception, i can update my database according to the response error message. the only thing keeping me from doing this is that i have a long list.. and for each one of them catching an exception and maintaining the application to carry on to the next contact in the mailing list may not be that much possible or optimized.. Please comment on this.. I have tried sending emails quite some time ago. and thank you for your help. i will only be able to decide about the success of this technique when i recieve the bounced messages into my mailbox. I guess, i will have to wait for the results.

Thanks a lot for your help.

Regards,
GaryFrancisLondCommented:
You are correct that sending e-mails in this way may cause a timeout of some sort when running over a web page. Maybe you can try changing the timeout of the page - not sure hwo this works though.

An alternative solution to this is not to write is as a web page and use it as a Win32 application or service. If you send your e-mail using objMessage.Send() and you don't catch the exception, your application will stop processing and give an exception message. Therefore you need to use the try{}catch{} block as you have done.

The way I do it in my application is that I create the e-mail and list of contacts within my web application, this is then passed onto a Windows Service which is constantly waiting for e-mails and sending them at a specified rate per minute in order to avoid killing my mail server. Thsi rate is also variable so that in the evenings and weekends I can send a larger number of e-maisl per minute.

As a guideline, before I used thie service approach I was able to send approximately 500 e-mails from a web page (whilst looping through a CSV file and extratincg 5 fields of information from each line) in 2 minutes (which appears to be the time it takes for the page to timeout.

Regards,

Gary Francis
Software Developer
*** URL removed by humeniuk PE ***

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
asifthakurAuthor Commented:
Thanks a lot for all that valueable information. I am sure i will be able to benefit from it. Thanks a lot Mr. Sammy.. My credit goes to both of you.  :-)

Regards,
SammyCommented:
I think Garry's approach is the best in this situation.
If you are not comfortable with using a windows service, you can use a web service and have it handle the task
asifthakurAuthor Commented:
Yes i agree, Creating a windows service can save the day. I intend to work on it tomorrow as i am off for the day. I hope to give you people some good news tomorrow.

Thanks,

Ali Akbar
SammyCommented:
Good luck Ali
asifthakurAuthor Commented:
Hello everyone,

Thanks a lot for being with me, but even after repeated efforts for that last 3-days I am unable to get any bounced emails on the specified address. As far as I know, the thing has to work correctly. But for some good reason, it is not.

Maybe some mismatch in environment settings. Or some parameters that we are passing. i have checked all the parameters and have been using the same parameters before.

I had confusion in the following.

If I run the code in a asp file.. it works fine. And I have been using it in an earlier asp project. The only difference is that It does not contain the following lines. Uncommenting them causes error.

objMessage.fields("urn:schemas:mailheader:disposition-notification-to") = "bounce_test@domain.com"

objMessage.fields("urn:schemas:mailheader:return-receipt-to") = "bounce_test@domain.com"

objMessage.Configuration.fields("urn:schemas:mailheader:return-path") = "bounce_test@domain.com"

objMessage.DSNOptions = CdoDSNOptions.cdoDSNFailure

Do you think there is something that keeps this component from performing on this platform.
e.g. some server settings or services that need to be running. I have a limited networking knowledge due to which I am so far not able to explain the problem specifically. I would be thankful if I can get some prerequisites or the system requirements for cdosys as there is a knowledge gap between me and the network administrator. I am not able to explain what is required or what to fix.

One more thing that can make my life easier is ' how to convert external (public) ip into internal ip' since we have the same mail and hosting server that is a dedicated machine running windows 2003 server. i have windows xp professional installed on my machine.

sorry for keeping you wait for 2 days.

Kind regards,

Ali.
asifthakurAuthor Commented:
Hello again,

I have just come to know that we are using plesk 7.5 for windows in our server running on windows 2003.

http://www.swsoft.com/plesk

we are not using exchange server. can someone confirm me if the code i have written only works on Exchange Server. Is there a way around for me to somehow get delivery status notifications.. any other server that i can install on my localhost to somehow simulate the mail server and get my cdosys start sending me bounced mails that i can use to update my addressbook.

Thanks a lot,

Ali
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.