473,289 Members | 1,963 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,289 software developers and data experts.

Send Email Message using C#

Atran
319 100+
Hello Everybody, I want to send a message to somebody email using C# I have the right code but when I run the application it shown the "ArgumentExecption was unhandled" error, it is been yellow, it stop the application from running.
Here is the code:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Net.Mail;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string to = "myEmail@hotmail.com";
  13.             string from = "myEmail@hotmail.com";
  14.             MailMessage message = new MailMessage(from, to);
  15.             message.Subject = "New Car";
  16.             message.Body = @"Hello Friend, I buy a new car today.";
  17.             SmtpClient client = new SmtpClient("MyServerName");
  18.             client.UseDefaultCredentials = true;
  19.             client.Send(message);
  20.         }
  21.     }
  22. }
  23.  
The code is true, but it doesnt send, and it shown the yello error when the code arrived to "client.Send(message)".
Can anyone help me.
May 27 '07 #1
8 14965
post the exact output of your exception.
May 27 '07 #2
What line is it throwing the error on?
May 28 '07 #3
Atran
319 100+
At "client.Send(message);" line, the program stop running, this is the exact error:

Expand|Select|Wrap|Line Numbers
  1. A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
  2.  

This is the all output text:

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\Ramsin Khoshaba\Local Settings\Application Data\Temporary Projects\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 0x194 has exited with code 0 (0x0).
  11. The thread 0xb88 has exited with code 0 (0x0).
  12. 'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\Ramsin Khoshaba\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe', Symbols loaded.
  13. 'ConsoleApplication1.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
  14. A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
  15.  
  16.  
thanks for anyhelp.
May 28 '07 #4
Your code runs fine on my system.
Likely your credentials.
Or maybe your hostname cannot be resolved??
May 28 '07 #5
Frinavale
9,735 Expert Mod 8TB
Hello Everybody, I want to send a message to somebody email using C# I have the right code but when I run the application it shown the "ArgumentExecption was unhandled" error, it is been yellow, it stop the application from running.
Here is the code:

Can anyone help me.
Could it be that your mail provider requires you to log in in order to use their services?

In this case you'll have to provide credentials in order to connect to the mail server.

Check out this .NET article on how to send an email for an example on how to provide email credentials.

Cheers!

-Frinny
May 28 '07 #6
Atran
319 100+
Thanks for yours help, But it still not work, I try that from many ways.
and how to connect to the mail server?
May 28 '07 #7
mwalts
38
Thanks for yours help, But it still not work, I try that from many ways.
and how to connect to the mail server?
Connecting to the mail server is pretty clearly defined in the Quick Reference linked above.

Based on your exception, I'm guessing you have .NET 2.0
That means you should look under the "if you are using .NET Framework version 2.0" section.

For connecting to the mail server, that is covered on the Net.Mail.SmtpClient lines.

It really is all there, if there is a line you don't understand, you can post that here and we can probably help you

-mwalts
May 28 '07 #8
Well, doesn't your mail provider give you support on how to set up a mail client like Outlook or Eudora?
If so, what settings do they tell you to use?

If you have a network administrator what do they tell you to use?
May 28 '07 #9

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

Similar topics

11
by: Google Mike | last post by:
I've got RH9 Linux with default PHP. Is there a way to send email on Linux to an Exchange Server from PHP and/or other tools when there is *NOT* SMTP access? Has anyone figured out a way to...
4
by: Filip Wtterwulghe | last post by:
Hello, We have a number of VB6 ActiveX applicationmodule(s) that are loaded into a IE6 WebBrowserControl . This WebControl is imbededded into Application X . Now We want to send a message from...
1
by: Gernot Hillier | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi! I'm the developer of a Linux ISDN application which uses embedded Python for controlling the communication. It starts several threads (i.e....
0
by: David Burson | last post by:
Hi, I have a VB.NET windows app that needs to automatically send a simple text email when my users run a new version of the app for the first time. I thought this would be simple, but after...
7
by: Randel Bjorkquist | last post by:
First, I'm extremely new to C# and the Microsoft Visual Studio IDE. I am in the middle of writing a small web application that communicates to a database server and sends out email confirmations. ...
9
by: Bob Jones | last post by:
We have developed a commercial ASP.net application (personal nutrition management and tracking); we want to send smtp email from within it. For our development box, we use WinXP Pro, IIS 5.5,...
1
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
4
by: barry | last post by:
Hi I a developing on a Windows 2003 Server environment with MS Exchange 2003 installed, using the following code i am able to send e-mail message to Administrator@myserver.com but not to any...
14
by: supz | last post by:
Hi, I use the standard code given below to send an email from an ASP.NET web form. The code executes fine but no Email is sent. All emails get queued in the Inetpub mail queue. I'm using my...
8
by: shapper | last post by:
Hello, I am trying to send an email using Asp.Net 2.0. I am getting the following error: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: No such...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
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: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.