tags:

views:

1782

answers:

5

I am working MS C# 2008. I created Windows form application. And I need to send email from my application. so how do I configure smtp settings?

EDIT

I got The following Exception

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

on smtp.send(message);

I have not installed IIS so is it required for desktop app?

+2  A: 

You can add the SMTP settings within the App.Config http://www.mitchelsellers.com/blogs/articletype/articleview/articleid/8/net-20-smtp-settings.aspx

And then use System.Net.Mail.SmtpClient and System.Net.Mail.MailMessage to send and create the emails.

c = new System.Net.Mail.SmtpClient();

msg = new System.Net.Mail.MailMessage();

System.Net.Mail.MailAddress a = new System.Net.Mail.MailAddress( sEmailAddress, sWho );

msg.To.Add( a );

msg.From = new System.Net.Mail.MailAddress("");

msg.ReplyTo = new System.Net.Mail.MailAddress("");

msg.Subject = "Web Inquiry";

msg.Body = msgBody.ToString();

c.Send( msg );
James_Dude
@riz00z - please always format code for readability. kthnx
IainMH
+1  A: 

Try this and then look here

Preet Sangha
+1  A: 

This is all covered in this msdn page:

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx

IainMH
+1  A: 

This person has done a nice tutorial: http://www.systemnetmail.com/

Matt Sherman
A: 

why are a lot of you that are making the "IIS" suggestions using this as the backbone to solve the problem? What if this is a deployed application? you going to have the client install and run IIS on their mediocre system just use the mail functionality of your app???

That doesn't make sense to me.

Those of you looking for a solution on sending emails thru win apps, do a google search on "using gmail to send email in c#".

-Rob