i have a problem : with sending email

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mahmodm3
    New Member
    • Jan 2009
    • 10

    i have a problem : with sending email

    (using System.Net.Mail )


    hi
    i have this code :
    Code:
            MailMessage myMail = new MailMessage("mail@mail.com", "mail@mail.com", "My Report.", "See the file.");
            SmtpClient myccc = new SmtpClient("localhost");
            myccc.Credentials = CredentialCache.DefaultNetworkCredentials;
            myccc.Send(myMail);
    its just tell me this message :
    Failure sending mail

    <edit by mod: replaced email addresses with fake ones for your privacy>
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    If you look at the details of the exception that is thrown you will see what SMTP command generated the error. that might tell you more about what went wrong.

    Comment

    • mahmodm3
      New Member
      • Jan 2009
      • 10

      #3
      i even look at it but its not helping
      please someone help me
      i need it so quick

      Comment

      • mldisibio
        Recognized Expert New Member
        • Sep 2008
        • 191

        #4
        Do you have a SMTP service installed and running as a Windows Service on the same machine defined as "localhost" ?

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Are you catching the exception as the base Exception or as an SmtpException?
          The SmtpException will give you extended information about the failure.

          Comment

          • mahmodm3
            New Member
            • Jan 2009
            • 10

            #6
            no i haven't SMTP runing

            sooo i need help give me a solution

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Well if you don't have an smtp server running, how do you expect to connect to it?

              Comment

              • mahmodm3
                New Member
                • Jan 2009
                • 10

                #8
                Well if you don't have an smtp server running, how do you expect to connect to it?
                then how can i run this thing ??

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  I can think of two ways:
                  Open up a command prompt (cmd)
                  and run:
                  net start "Simple Mail Transfer Protocol (SMTP)"

                  Or run services.msc and look for the SMTP service and start it.

                  Comment

                  • mahmodm3
                    New Member
                    • Jan 2009
                    • 10

                    #10
                    I can think of two ways:
                    Open up a command prompt (cmd)
                    and run:
                    net start "Simple Mail Transfer Protocol (SMTP)"

                    Or run services.msc and look for the SMTP service and start it.

                    I do like you said but its not working
                    i run in cmd : net start
                    then i run the code but the same problem

                    Comment

                    • jg007
                      Contributor
                      • Mar 2008
                      • 283

                      #11
                      some more information would help as we can guess from the code but this may not always be correct as you may have just found the code and be trying to use it incorrectly

                      are you trying to send on a network that is using exchange servers?

                      are you trying to send from a specific smtp server?

                      if you are connecting to a smtp server where are you intending to get the logon details from as with exchange you can use your standard network credentials but I don't think you can with SMTP

                      I have sent some stuff via exchange so don't have a lot of experience with doing smtp but this information will help clarify things a bit

                      Comment

                      • mahmodm3
                        New Member
                        • Jan 2009
                        • 10

                        #12
                        so i don't understand what are you mean exactly
                        but if you have another code than can i send an email please
                        tell me what is it

                        Comment

                        • jg007
                          Contributor
                          • Mar 2008
                          • 283

                          #13
                          I haven't got an exchange server at home to work out the code but try having a look at this thread -



                          if you have any problems I will try setting something up to work it out.

                          Comment

                          • jg007
                            Contributor
                            • Mar 2008
                            • 283

                            #14
                            also you are pointing to your SMTP server as ' localhost ' which will redirect back to your PC, if you check the code you will see that it will usually point to a server running either exchange or an SMTP server, to confirm if it is runnning smtp you could try using telnet on port 25 unless it is set up for a different port

                            Comment

                            • vekipeki
                              Recognized Expert New Member
                              • Nov 2007
                              • 229

                              #15
                              If you are making a WinForms app, you can do it using MAPI, and use MS Outlook (or other mail client) to send your mails.

                              Google for ".NET MAPI" (e.g. http://www.codeproject.com/KB/IP/SendFileToNET.aspx).

                              This way you don't have to worry about the SMTP server, but rather pass the mail to Outlook, which will then use its own stored account settings.

                              Comment

                              Working...