using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Net.Mail; namespace YourNameSpace { /// /// Helper class for sending mail /// public class Helper { public Helper() { // // TODO: Add constructor logic here // } public static bool SendMailMessage(string SMTPServer, string fromAddress, string fromName, string toAddress, string toName, string msgSubject, string msgBody, bool IsBodyHtml) { // Use the new v2.0 mail class to send an E-mail. try { SmtpClient client = new SmtpClient(SMTPServer); MailAddress from = new MailAddress(fromAddress, fromName); MailAddress to = new MailAddress(toAddress, toName); MailMessage message = new MailMessage(from, to); message.Subject = msgSubject; message.IsBodyHtml = IsBodyHtml; message.Body = msgBody; client.Send(message); } catch (System.Net.Mail.SmtpException) { throw; } catch (Exception) { throw; } return true; } public static bool SendMailMessageWithAttachment(string SMTPServer, string fromAddress, string fromName, string toAddress, string toName, string msgSubject, string msgBody, bool IsBodyHtml, string AttachmentFile) { try { SmtpClient client = new SmtpClient(SMTPServer); MailAddress from = new MailAddress(fromAddress, fromName); MailAddress to = new MailAddress(toAddress, toName); MailMessage message = new MailMessage(from, to); message.Subject = msgSubject; message.IsBodyHtml = IsBodyHtml; message.Body = msgBody; Attachment at = new Attachment(AttachmentFile); message.Attachments.Add(at); client.Send(message); } catch (System.Net.Mail.SmtpException e) { } catch (Exception e) { } return true; } } // Class } // Namespace