473,324 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 -
Expand|Select|Wrap|Line Numbers
  1. '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.
  2. '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.
  3. '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.
  4. '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.
  5. '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.
  6. '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.
  7. '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.
  8. '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.
  9. '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.
  10. The thread 0xce0 has exited with code 0 (0x0).
  11. 'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\shilpi\My Documents\Visual Studio 2005\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe', Symbols loaded.
  12. '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.
  13. '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.
  14. The thread 0x1030 has exited with code 0 (0x0).
  15. The thread 0x1588 has exited with code 0 (0x0).
  16. The program '[6060] ConsoleApplication1.vshost.exe: Managed' has exited with code 0 (0x0).
  17.  


Here's the code:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace SendMail
  6. {
  7.     using System;
  8.     class Class1
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             try
  13.             {
  14.                 CDO.Message oMsg = new CDO.Message();
  15.                 CDO.IConfiguration iConfg;
  16.  
  17.                 iConfg = oMsg.Configuration;
  18.  
  19.                 ADODB.Fields oFields;
  20.                 oFields = iConfg.Fields;
  21.  
  22.                 // Set configuration.
  23.                 ADODB.Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
  24.  
  25.                 //TODO: To send by using the smart host, uncomment the following lines:
  26.                 //oField.Value = CDO.CdoSendUsing.cdoSendUsingPort;
  27.                 //oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
  28.                 //oField.Value = "smarthost";
  29.  
  30.                 // TODO: To send by using local SMTP service.
  31.                 oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
  32.                 oField.Value = 2;
  33.                 oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
  34.                 oField.Value = "localhost";
  35.                 oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
  36.                 oField.Value = 25;
  37.                 oFields.Update();
  38.  
  39.                 // Set common properties from message.
  40.  
  41.                 //TODO: To send text body, uncomment the following line:
  42.                 oMsg.TextBody = "Hello, how are you doing?";
  43.  
  44.  
  45.                 oMsg.Subject = "Test SMTP";
  46.  
  47.                 //TODO: Change the To and From address to reflect your information.                      
  48.                 oMsg.From = "minishilpi@gmail.com";
  49.                 oMsg.To = "minishilpi@gmail.com";
  50.                 oMsg.Send();
  51.             }
  52.             catch (Exception e)
  53.             {
  54.                 Console.WriteLine("{0} Exception caught.", e);
  55.             }
  56.         }
  57.     }
  58. }
  59.  
Thank you for your help!
Mar 21 '09 #1
11 4422
tlhintoq
3,525 Expert 2GB
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.
Mar 21 '09 #2
tlhintoq
3,525 Expert 2GB
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?
Mar 21 '09 #3
tlhintoq
3,525 Expert 2GB
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?
Mar 21 '09 #4
madankarmukta
308 256MB
Hi,

Is the code getting compiled...?

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

Could you please answer ..?

Thanks!
Mar 22 '09 #5
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.
Mar 23 '09 #6
Frinavale
9,735 Expert Mod 8TB
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
Mar 23 '09 #7
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.
Mar 24 '09 #8
Frinavale
9,735 Expert Mod 8TB
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?
Mar 24 '09 #9
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.
Mar 24 '09 #10
Frinavale
9,735 Expert Mod 8TB
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
Mar 24 '09 #11
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: <someSMTPAddress@domain.com> (enter) (this should be a valid email domain on your localhost or within your organization)
4) RCPT TO: <someuserthatyouaresendingemailto@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.
Mar 24 '09 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: joe215 | last post by:
I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using...
3
by: Ant | last post by:
Hi, I'm using the MailMessage & smtpMail classes in System.Web.Mail to send mail, however it's not sending any emails. I'm using it on a Windows 2003 server. The simplest way to use this is...
6
by: Anuradha | last post by:
Dear All How can i send mails using vb.net Thanx all
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
4
by: InnoCreate | last post by:
Hi Everyone, I've added an error handler to some code and as part for the routine it logs to the application log and then sends the administrator an email. For some reason this email isn't...
9
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient...
7
by: undbund | last post by:
Hi I am creating a newsletter system. The software should run from desktop computer (localhost) but be able to send email to anyone on the internet. Can you guys give me some ideas on how to...
10
by: Markgoldin | last post by:
I am sending an XML data from not dontnet process to a .Net via socket listener. Here is a data sample: <VFPData> <serverdata> <coderun>updateFloor</coderun> <area>MD2</area>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.