The System.Net.Mail namespace contains all the classes required for sending mail
from within a .NET application.
The SmtpClient class handles the actual sending of e-mail. For a simple mail,
you can directly pass in the To address, from, subject, and body of the mail to
one of the SmtpClient's overloaded send methods.
Client application:
private void btnSendMail_Click(object sender, EventArgs e)
{
MailService service = new MailService();
string from = "some@yahoo.com";
string to = "some@yahoo.com";
string subject = "Sending EMails from .NET 2.0";
string body = "Message Body";
service.SendMail(from, to, subject, body); ;
MessageBox.Show("Done");
}
Sending method:
public void SendMail(string from, string to,
string subject, string body)
{
string mailServerName = "yoursmtpserver";
try
{
//MailMessage represents the e-mail being sent
using (MailMessage message = new MailMessage(from,
to, subject, body))
{
message.IsBodyHtml = true;
SmtpClient mailClient = new SmtpClient();
mailClient.Host = mailServerName;
mailClient.UseDefaultCredentials = true;
mailClient.DeliveryMethod =
SmtpDeliveryMethod.PickupDirectoryFromIis;
//Send delivers the message to the mail server
mailClient.Send(message);
}
}
catch (SmtpException ex)
{
throw new ApplicationException
("SmtpException occurred: " + ex.Message);
}
catch (Exception ex)
{
throw ex;
}
}
More information like CC,BCC, Attachments can be found at:
http://www.codeguru.com/csharp/csharp/cs_misc/e-mail/article.php/c9957__1/
Reflector for .Net - Reflector is the class browser, explorer, analyzer and documentation viewer for .NET. Reflector allows to easily view, navigate, search, decompile and analyze .NET assemblies in C#, Visual Basic and IL. At same site there are also other interesting tools like: Resourcer for .NET - Resourcer is an editor for .resources binaries and .resX XML file formats used with the .NET platform Mapack for .NET - Mapack is a .NET class library for basic linear algebra computations.
Comments