473,473 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Send Email Message using C#

Atran
319 Contributor
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 14977
oohay251
27 New Member
post the exact output of your exception.
May 27 '07 #2
myrrdin
6 New Member
What line is it throwing the error on?
May 28 '07 #3
Atran
319 Contributor
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
oohay251
27 New Member
Your code runs fine on my system.
Likely your credentials.
Or maybe your hostname cannot be resolved??
May 28 '07 #5
Frinavale
9,735 Recognized Expert Moderator Expert
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 Contributor
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 New Member
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
oohay251
27 New Member
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.