sending email using C# - exited with code 0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • minishilpi
    New Member
    • Mar 2009
    • 3

    sending email using C# - exited with code 0

    I have a question - I have this code below to send an email and I have referenced the Microsoft CDO Library 2000.
    It doesn't throw any exception in the console window. It goes throughout the code successfully, but I do not receive any email.
    When I execute this code to send email, it gives the following error -
    Code:
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\shilpi\My Documents\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    The thread 0xce0 has exited with code 0 (0x0).
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\shilpi\My Documents\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe', Symbols loaded.
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\shilpi\My Documents\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\Interop.CDO.dll', No symbols loaded.
    'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\shilpi\My Documents\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\Interop.ADODB.dll', No symbols loaded.
    The thread 0x1030 has exited with code 0 (0x0).
    The thread 0x1588 has exited with code 0 (0x0).
    The program '[6060] ConsoleApplication1.vshost.exe: Managed' has exited with code 0 (0x0).


    Here's the code:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace SendMail
    {
        using System;
        class Class1
        {
            static void Main(string[] args)
            {
                try
                {
                    CDO.Message oMsg = new CDO.Message();
                    CDO.IConfiguration iConfg;
    
                    iConfg = oMsg.Configuration;
    
                    ADODB.Fields oFields;
                    oFields = iConfg.Fields;
    
                    // Set configuration.
                    ADODB.Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
    
                    //TODO: To send by using the smart host, uncomment the following lines:
                    //oField.Value = CDO.CdoSendUsing.cdoSendUsingPort;
                    //oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
                    //oField.Value = "smarthost";
    
                    // TODO: To send by using local SMTP service.
                    oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
                    oField.Value = 2;
                    oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
                    oField.Value = "localhost";
                    oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
                    oField.Value = 25;
                    oFields.Update();
    
                    // Set common properties from message.
    
                    //TODO: To send text body, uncomment the following line:
                    oMsg.TextBody = "Hello, how are you doing?";
    
    
                    oMsg.Subject = "Test SMTP";
    
                    //TODO: Change the To and From address to reflect your information.                      
                    oMsg.From = "minishilpi@gmail.com";
                    oMsg.To = "minishilpi@gmail.com";
                    oMsg.Send();
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Exception caught.", e);
                }
            }
        }
    }
    Thank you for your help!
    Last edited by tlhintoq; Mar 21 '09, 08:08 PM. Reason: [CODE] tags added
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      When I execute this code to send email, it gives the following error -
      What you show as an error isn't an error. Its just the history of the application running.

      I suspect you just copy/pasted a big chuck of code from someplace and expected it to work.

      You are lacky many 'using' statements.
      Have reverenced many objects such as CDO that simply don't exist in the program as shown.
      What did the console output as the exception error when it hit line 54?

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        I just looked at the title of your post..
        "sending email using C# - exited with code 0"

        Do you think this message indicates an error?
        Is this the first program you've built in Visual Studio?

        Comment

        • madankarmukta
          Contributor
          • Apr 2008
          • 308

          #5
          Hi,

          Is the code getting compiled...?

          Did you added the proper reference..? Which reference you added..?

          Could you please answer ..?

          Thanks!
          Last edited by tlhintoq; Mar 22 '09, 04:18 PM. Reason: No need to quote the entire long original post

          Comment

          • stoogots2
            New Member
            • Sep 2007
            • 77

            #6
            Assuming there is no error, check the local machine for email. If the mail server doesn't know the destination server/domain, or has routing disabled, email will sit on the server. If this is the case, you will need to change "localhost" to a valid relay server.

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              You know, there is a nifty little quick reference on how to send an email using .NET that explains how to send an email that doesn't depend on the Microsoft CDO Library 2000....

              -Frinny

              Comment

              • minishilpi
                New Member
                • Mar 2009
                • 3

                #8
                tlhintoq: there were no exceptions on line 54 of the code. You are right, about it not being an error. I did receive the emails, but they were delayed by 3 days. Do you have any ideas as to why?

                stoogots2: I am using the default SMTP server. How can I find out if it is aware of the destination server/domain, or has routing disabled?

                I have added my ip address to the relay server list. So do you want me to use my ip address instead of using localhost?

                madankarmukta: The code is being compiled fine and there were no errors.

                Frinavale: I tried using that code too, but it exited with code 0. And I still hav'nt received the email. Maybe I will receive it after a couple of days.

                Comment

                • Frinavale
                  Recognized Expert Expert
                  • Oct 2006
                  • 9749

                  #9
                  I've never experienced "days" of delay like you are.
                  Are you sure it isn't your email provider that's not working?
                  Have you tried using a different one? Like hotmail or gmail?

                  Comment

                  • minishilpi
                    New Member
                    • Mar 2009
                    • 3

                    #10
                    I have included the code in the website and hosted the website. Now the same code sends emails immediatley.

                    The code when executed locally has a very long delay (2-3 days).

                    So, this definitely has something to do with the Default SMTP virtual server I am using under IIS.

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      I'm glad it's working for you in the wild.
                      It's going to make testing while developing difficult though.
                      For development testing purposes would recommend using a different SMTP server than you are currently using...or look into fixing it.

                      Cheers!
                      -Frinny

                      Comment

                      • stoogots2
                        New Member
                        • Sep 2007
                        • 77

                        #12
                        Pretty interesting. I thought that by default SMTP messages timed out and generated Non-Delivery reports after 48 hours, but I guess I could be wrong. I think MS-Exchange does this by default.

                        Sounds like this is an email routing issue. Determine what domain you are sending email to and grab one of the email addresses, and the servername that you are sending from (you can't use localhost).

                        Then do this from the SMTP mail server. You should get a list of responsible servers for the recipients domain and then you can check connectivity to those mail servers that are finally listed.

                        1) NSLOOKUP (type from command prompt and press enter)
                        2) SET TYPE=MX (enter),
                        3) somedomain.com (enter)

                        then try from a different command window (but on the SMTP server itself). You are going to send a simple test email via Telnet.

                        1) TELNET hostname 25 (enter)
                        (where hostname is one of the results from your NSLOOKUP)
                        2) HELO yourservername (enter)
                        3) MAIL FROM: <someSMTPAddres s@domain.com> (enter) (this should be a valid email domain on your localhost or within your organization)
                        4) RCPT TO: <someuserthatyo uaresendingemai lto@domain.com> (enter)
                        5) DATA (enter)
                        6) Subject: Some Subject (enter)
                        7) Some text in the message (enter)
                        8 . (enter)
                        (the period in the blank line means end of message)
                        If you get a message accepted message, your message is on its way.

                        Anyway, if there is an error anywhere in your typing you will get a 500+ error you have probably typed something improperly, or the destination server is not accepting email from you.

                        Let me know what happens.

                        Comment

                        Working...