public class Mail
{
private System.Net.Mail.MailMessage _mail = new System.Net.Mail.MailMessage();
public Mail(string fromName, string fromMail, string toName, string toMail, string subject, string body, bool isHtml)
{
this._mail.Subject = subject;
this._mail.Body = body;
this._mail.From = new System.Net.Mail.MailAddress(fromMail, fromName);
this._mail.To.Add(new System.Net.Mail.MailAddress(toMail, toName));
this._mail.IsBodyHtml = isHtml;
this._mail.BodyEncoding = System.Text.Encoding.GetEncoding(“iso-8859-1”);
this._mail.SubjectEncoding = System.Text.Encoding.GetEncoding(“iso-8859-1”);
}
public bool Send()
{
try
{
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(“localhost”); // Mettre le serveur smtp ici
smtp.Send(this._mail);
return true;
}
catch (Exception) { return false; }
}
}
//Exemple:
// Mail m = new Mail(“MonMail”, “MonMail@domain.com”, “UnCopain”, “MailDuCopain@domain.com”, “Le sujet de mon mail”, “Le corp du message qui peut être en HTML si on met le paramètre ‘isHTML’ à True”, false);
// m.Send();