Sending an email from C# winforms application is exactly same as we do in webapps using System.Net.Mail namespace. Here is a sample code which sends out an email with an attachment (again it is not specific to winforms can be used in webapps as it is).
MailMessage msg = new MailMessage(); if (varEmailID.IndexOf(',') > 0) msg.Attachments.Add(attach); string FromEmail = ConfigurationSettings.AppSettings["SystemMailID"]; msg.From = new MailAddress(FromEmail); client.Send(msg);
SmtpClient client;
Attachment attach = new Attachment(filepath);
{
string[] iDs;
iDs = varEmailID.Split(',');
for (int i = 0; i <= iDs.Length - 1; i++)
{
msg.To.Add(new MailAddress(iDs.GetValue(i).ToString()));
}
}
else
{
msg.To.Add(new MailAddress(varEmailID));
}
msg.Subject = varSubject;
msg.Body = varBody;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.Normal;
string SmtpServer = ConfigurationSettings.AppSettings["SmtpServer"];
string UserName = ConfigurationSettings.AppSettings["UserName"];
string Password = ConfigurationSettings.AppSettings["Password"];
client = new SmtpClient(SmtpServer);
client.UseDefaultCredentials = false;
System.Net.NetworkCredential creds = new System.Net.NetworkCredential(UserName, Password);
client.Credentials = creds;