Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Cannot send all mails by SmtpClient.Send method until process is killed

Cannot send all mails by SmtpClient.Send method until process is killed

Scheduled Pinned Locked Moved C#
csharphelpasp-netsysadmintesting
9 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    debnarayan
    wrote on last edited by
    #1

    Hi all, I tried to write a mail queuer with C#. At the Mail Sending step, I am using smtpClient.Send(mailMessage) call. The call is not throwing exception. The application is made to wait by a Console.Read() call after sending all the mails in a loop. [I have tried with 10, 100, 2500 mails at different shots] But 100% of the mails I have sent do not reach my mailbox when the application waits at the Console.Read(). However, as soon as I hit enter, all the pending mails are sent. But I need this app to run on a webserver. While testing the same code as WebService, I had to restart the server [ASP.NET Development Server] to send those pending mails. Now I am at a fix, because my smtpClient.Send() methods are fired nicely without any exception, but probably the mails are queued at some other end, which I don't know how to flush. Please help. Thanks in advance. Deb

    A P D D 4 Replies Last reply
    0
    • D debnarayan

      Hi all, I tried to write a mail queuer with C#. At the Mail Sending step, I am using smtpClient.Send(mailMessage) call. The call is not throwing exception. The application is made to wait by a Console.Read() call after sending all the mails in a loop. [I have tried with 10, 100, 2500 mails at different shots] But 100% of the mails I have sent do not reach my mailbox when the application waits at the Console.Read(). However, as soon as I hit enter, all the pending mails are sent. But I need this app to run on a webserver. While testing the same code as WebService, I had to restart the server [ASP.NET Development Server] to send those pending mails. Now I am at a fix, because my smtpClient.Send() methods are fired nicely without any exception, but probably the mails are queued at some other end, which I don't know how to flush. Please help. Thanks in advance. Deb

      A Offline
      A Offline
      Andrei Ungureanu
      wrote on last edited by
      #2

      Try using the async version of the Read method. And you should also treat the SendCompleted event. It's better using the async version because your application doesn't hang while the mails are being sent. Hope it helps.

      There are 10 kinds of people: those who understand binary and those who don't

      D 1 Reply Last reply
      0
      • A Andrei Ungureanu

        Try using the async version of the Read method. And you should also treat the SendCompleted event. It's better using the async version because your application doesn't hang while the mails are being sent. Hope it helps.

        There are 10 kinds of people: those who understand binary and those who don't

        D Offline
        D Offline
        debnarayan
        wrote on last edited by
        #3

        Hi, Thanks for the reply. "Try using the async version of the Read method." -- I hope you meant SendAsync method. I have already tried with the SendAsync method, and handled the callback. But it was of no help. So I have implemented another part of the application with asynchronous delegate invoke, to release the caller/client instantly, while the Send operation part is synchronous. I think either the Framework, or the OS is maintaining a buffer somewhere, which is getting flushed when the process terminates. However this is what I think, and I can't solve this problem right now. Thanks, Deb

        1 Reply Last reply
        0
        • D debnarayan

          Hi all, I tried to write a mail queuer with C#. At the Mail Sending step, I am using smtpClient.Send(mailMessage) call. The call is not throwing exception. The application is made to wait by a Console.Read() call after sending all the mails in a loop. [I have tried with 10, 100, 2500 mails at different shots] But 100% of the mails I have sent do not reach my mailbox when the application waits at the Console.Read(). However, as soon as I hit enter, all the pending mails are sent. But I need this app to run on a webserver. While testing the same code as WebService, I had to restart the server [ASP.NET Development Server] to send those pending mails. Now I am at a fix, because my smtpClient.Send() methods are fired nicely without any exception, but probably the mails are queued at some other end, which I don't know how to flush. Please help. Thanks in advance. Deb

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          I wrote a Windows Service to send email. My applications put the necessary information in a database table, the emailer reads the table and sends the emails.

          D 1 Reply Last reply
          0
          • P PIEBALDconsult

            I wrote a Windows Service to send email. My applications put the necessary information in a database table, the emailer reads the table and sends the emails.

            D Offline
            D Offline
            debnarayan
            wrote on last edited by
            #5

            Yes, obviously writing a windows service is possible, but I need it as a WebService. However, I can use other approaches as well, but I need to send all the mails. As also, due to certain constraints, I can't use database, or even flat files for mail sending. I am using a derived Queue with an overloaded EnQueue method, which fires a delegate whenever any item is added to the queue. My problem is that, even if the smtpClient.Send call is executed successfully, all the mails are not sent until the running thread/process is killed. I can't understand the cause of the problem. Say I fired Send method 100 times. I am getting no exceptions, and all 100 calls are going through fine. But all 100 mails are not sent until I close the process from which Send method is fired. It will be very helpful, if I atleast get an explanation why this is happening, if not how to solve this. Thanks. Deb

            1 Reply Last reply
            0
            • D debnarayan

              Hi all, I tried to write a mail queuer with C#. At the Mail Sending step, I am using smtpClient.Send(mailMessage) call. The call is not throwing exception. The application is made to wait by a Console.Read() call after sending all the mails in a loop. [I have tried with 10, 100, 2500 mails at different shots] But 100% of the mails I have sent do not reach my mailbox when the application waits at the Console.Read(). However, as soon as I hit enter, all the pending mails are sent. But I need this app to run on a webserver. While testing the same code as WebService, I had to restart the server [ASP.NET Development Server] to send those pending mails. Now I am at a fix, because my smtpClient.Send() methods are fired nicely without any exception, but probably the mails are queued at some other end, which I don't know how to flush. Please help. Thanks in advance. Deb

              D Offline
              D Offline
              Dan Neely
              wrote on last edited by
              #6

              does your app terminate after the Console.Read()? If so you're right about it being a buffer issue. Check the smtpClient class for a Flush method. IF for some reason there isn't one the Close or Dispose methods will do the same thing as shutting down the app. Just remember you'll need to reallocate a new smtpClient the next time you need to send.

              -- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.

              D 1 Reply Last reply
              0
              • D Dan Neely

                does your app terminate after the Console.Read()? If so you're right about it being a buffer issue. Check the smtpClient class for a Flush method. IF for some reason there isn't one the Close or Dispose methods will do the same thing as shutting down the app. Just remember you'll need to reallocate a new smtpClient the next time you need to send.

                -- If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.

                D Offline
                D Offline
                debnarayan
                wrote on last edited by
                #7

                Yes, the app terminates after the Console.Read(). I am still in problem as SmtpClient class has no flush method. And I cannot Dispose off any client, as there is an implementation of client pooling. So I am creating the clients with identical credentials, and Host settings, and maintaining a queue of specified number of clients. I am thinking of recreating the client list after some idle time, but I am not sure. But is it really some buffer issue at the SmtpClient end, or at some other end? Because if it is at some other end, I am not sure whether disposing off the clients will flush it. And where is the buffer? Deb

                1 Reply Last reply
                0
                • D debnarayan

                  Hi all, I tried to write a mail queuer with C#. At the Mail Sending step, I am using smtpClient.Send(mailMessage) call. The call is not throwing exception. The application is made to wait by a Console.Read() call after sending all the mails in a loop. [I have tried with 10, 100, 2500 mails at different shots] But 100% of the mails I have sent do not reach my mailbox when the application waits at the Console.Read(). However, as soon as I hit enter, all the pending mails are sent. But I need this app to run on a webserver. While testing the same code as WebService, I had to restart the server [ASP.NET Development Server] to send those pending mails. Now I am at a fix, because my smtpClient.Send() methods are fired nicely without any exception, but probably the mails are queued at some other end, which I don't know how to flush. Please help. Thanks in advance. Deb

                  D Offline
                  D Offline
                  debnarayan
                  wrote on last edited by
                  #8

                  Hello all, I found an answer to my question. The bufferring is done by Norton Antivius Email-Scanner. The possible solutions I found from MSDN Blog is to set the SmtpClient.ServicePoint.MaxIdleTime = 1 or 60, etc and/or SmtpClient.ServicePoint.ConnectionLimit = 1, etc. Personally I tried with SmtpClient.TimeOut = 60 and 120 and that worked with certain TimeOut exceptions which I had to handle. Here are the link to the posts in MSDN: MSDN: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=164793&SiteID=1&PageID=1[^] Channel9: http://channel9.msdn.com/ShowPost.aspx?PostID=349773#349773[^]

                  S 1 Reply Last reply
                  0
                  • D debnarayan

                    Hello all, I found an answer to my question. The bufferring is done by Norton Antivius Email-Scanner. The possible solutions I found from MSDN Blog is to set the SmtpClient.ServicePoint.MaxIdleTime = 1 or 60, etc and/or SmtpClient.ServicePoint.ConnectionLimit = 1, etc. Personally I tried with SmtpClient.TimeOut = 60 and 120 and that worked with certain TimeOut exceptions which I had to handle. Here are the link to the posts in MSDN: MSDN: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=164793&SiteID=1&PageID=1[^] Channel9: http://channel9.msdn.com/ShowPost.aspx?PostID=349773#349773[^]

                    S Offline
                    S Offline
                    Suj_78
                    wrote on last edited by
                    #9

                    hi guys, i am stuck with this problem for last 2 days, i have set the timeout property to 60 , still it does not send emails untilli uninstall the service. please help!

                    happy coding!

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups