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
  1. Home
  2. General Programming
  3. C#
  4. Connection open while sending Email with SmtpClient

Connection open while sending Email with SmtpClient

Scheduled Pinned Locked Moved C#
question
17 Posts 3 Posters 0 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.
  • C coolestCoder

    Sagar K. Godbole wrote:

    does it open connection each time I do .Send()

    I dont think you mean to say that you need only 1 connection until all the mails you want to send are handed over ? If this is the case then you might be unhappy that there is no setting which can persist the connection. ( though i havent checked it myself, it is my perception )


    "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


    coolestCoder

    L Offline
    L Offline
    logicaldna
    wrote on last edited by
    #4

    yes i meant that. .send() is a blocking call. i need to send mails at one go with one connection, this is to get rid of Timeout wait in .Send() which takes place for each Mail that i need to send and if there are too many then its that much of wait for my application,

    ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

    E C 2 Replies Last reply
    0
    • E ednrgc

      So, you want to delay the sending of emails until a determine time?

      L Offline
      L Offline
      logicaldna
      wrote on last edited by
      #5

      coolestCoder wrote:

      mean to say that you need only 1 connection until all the mails you want to send are handed over

      this is what i mean ! Is it possible !

      ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

      1 Reply Last reply
      0
      • L logicaldna

        yes i meant that. .send() is a blocking call. i need to send mails at one go with one connection, this is to get rid of Timeout wait in .Send() which takes place for each Mail that i need to send and if there are too many then its that much of wait for my application,

        ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

        E Offline
        E Offline
        ednrgc
        wrote on last edited by
        #6

        If it's a problem, why not send it in another thread?

        L 1 Reply Last reply
        0
        • E ednrgc

          If it's a problem, why not send it in another thread?

          L Offline
          L Offline
          logicaldna
          wrote on last edited by
          #7

          i have arround 300-500 notifications to send at one go.. do you mean those many Threds...:sigh: I thought i could do a single connect and if it fails i will come to know immidiately.... right now ihave a collection of MailMessage objects which i'mpreparing in advanc and then sending it one by one Thanks,

          ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

          E C 2 Replies Last reply
          0
          • L logicaldna

            i have arround 300-500 notifications to send at one go.. do you mean those many Threds...:sigh: I thought i could do a single connect and if it fails i will come to know immidiately.... right now ihave a collection of MailMessage objects which i'mpreparing in advanc and then sending it one by one Thanks,

            ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

            E Offline
            E Offline
            ednrgc
            wrote on last edited by
            #8

            Do they all have the same content?

            L 1 Reply Last reply
            0
            • E ednrgc

              Do they all have the same content?

              L Offline
              L Offline
              logicaldna
              wrote on last edited by
              #9

              no , notifications are per action like Task Created,User registed etc.. if they are same is there way to do bulk send? thanks,

              ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

              E 1 Reply Last reply
              0
              • L logicaldna

                yes i meant that. .send() is a blocking call. i need to send mails at one go with one connection, this is to get rid of Timeout wait in .Send() which takes place for each Mail that i need to send and if there are too many then its that much of wait for my application,

                ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

                C Offline
                C Offline
                coolestCoder
                wrote on last edited by
                #10

                Hi, There is a SendAsync method, which is of your use, i think. check this article[^]


                "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


                coolestCoder

                L 1 Reply Last reply
                0
                • L logicaldna

                  no , notifications are per action like Task Created,User registed etc.. if they are same is there way to do bulk send? thanks,

                  ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

                  E Offline
                  E Offline
                  ednrgc
                  wrote on last edited by
                  #11

                  Yes, add the people to the "to" list. Instead of one email per recipient, add them to the recipient list, and send one email.

                  L 1 Reply Last reply
                  0
                  • L logicaldna

                    i have arround 300-500 notifications to send at one go.. do you mean those many Threds...:sigh: I thought i could do a single connect and if it fails i will come to know immidiately.... right now ihave a collection of MailMessage objects which i'mpreparing in advanc and then sending it one by one Thanks,

                    ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

                    C Offline
                    C Offline
                    coolestCoder
                    wrote on last edited by
                    #12

                    Hi, I thought this would also be of your interest. http://www.codeproject.com/cs/internet/smartmassemail.asp[^]


                    "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


                    coolestCoder

                    L 1 Reply Last reply
                    0
                    • E ednrgc

                      Yes, add the people to the "to" list. Instead of one email per recipient, add them to the recipient list, and send one email.

                      L Offline
                      L Offline
                      logicaldna
                      wrote on last edited by
                      #13

                      ;P well thanks, but thats the way emails are already generated, with multiple To,CC addresses..

                      ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

                      E 1 Reply Last reply
                      0
                      • C coolestCoder

                        Hi, There is a SendAsync method, which is of your use, i think. check this article[^]


                        "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


                        coolestCoder

                        L Offline
                        L Offline
                        logicaldna
                        wrote on last edited by
                        #14

                        thanks, internally it will spawn a thread to do my work, this will definately fasten up things, but if i can get that single connection for sending mails it will be great SmtpConnection class is there but its not exposed otherwise i could have achived behaviour seamlessly.

                        ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

                        1 Reply Last reply
                        0
                        • L logicaldna

                          ;P well thanks, but thats the way emails are already generated, with multiple To,CC addresses..

                          ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

                          E Offline
                          E Offline
                          ednrgc
                          wrote on last edited by
                          #15

                          You can also eliminate the round trip throught the server:

                          SmtpMail.SmtpServer = "localhost";
                          eMail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"]=1;
                          eMail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"] = "C:\\Inetpub\\mailroot\\Pickup";
                          SmtpMail.Send(eMail);

                          L 1 Reply Last reply
                          0
                          • E ednrgc

                            You can also eliminate the round trip throught the server:

                            SmtpMail.SmtpServer = "localhost";
                            eMail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"]=1;
                            eMail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory"] = "C:\\Inetpub\\mailroot\\Pickup";
                            SmtpMail.Send(eMail);

                            L Offline
                            L Offline
                            logicaldna
                            wrote on last edited by
                            #16

                            edboe wrote:

                            SmtpMail.SmtpServer = "localhost";

                            its from System.Web.Mail which has been depricated now.

                            ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

                            1 Reply Last reply
                            0
                            • C coolestCoder

                              Hi, I thought this would also be of your interest. http://www.codeproject.com/cs/internet/smartmassemail.asp[^]


                              "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


                              coolestCoder

                              L Offline
                              L Offline
                              logicaldna
                              wrote on last edited by
                              #17

                              i have gone through that already,but working with MSSQL 2000 i do not have sql server 2005 nice article though,. thanks

                              ------------------------------ Its not the fall that kills you; it's the sudden stop at the end.

                              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