private void SendEmail(string host, int port,
string username, string password,
string from, string to,
string subject, string body,
ICollection attachedFiles)
{
//A MailMessage object must be disposed!
using (MailMessage message = new MailMessage())
{
message.From = new MailAddress(from);
message.To.Add(to);
message.Subject = subject;
message.Body = body;
foreach (string file in attachedFiles)
{
message.Attachments.Add(new Attachment(file));
}
SmtpClient client = new SmtpClient(host, port);
//if your SMTP server requires a password,
//the following line is important
client.Credentials = new NetworkCredential(username, password);
//this send is synchronous. You can also choose
//to send asynchronously
client.Send(message);
}
}