Voorbeeld mail Class

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.Collections.Generic;

{
/// 
/// The Mail wrapper class, a wrapper for the .Net SmtpClient
/// 
public class Mail
{
/// 
/// Create a new instance of the Mail wrapper class
/// 
public Mail()
{
}
/// 
/// E-mail address of the sender
/// 
public string From = "";
/// 
/// Name of the sender
/// 
public string FromName = "";
/// 
/// List of e-mail addresses the e-mail should be sent to
/// 
public List To = new List();
/// 
/// List of e-mail addresses the e-mail should be carbon copied to (cc)
/// 
public List Cc = new List();
/// 
/// List of e-mail addresses the e-mail should be blank carbon copied to (bcc)
/// 
public List Bcc = new List();
/// 
/// The subject of the e-mail
/// 
public string Subject = "";
/// 
/// The body (content) of the e-mail
/// 
public string Body = "";
/// 
/// The host url of the e-mail provider
/// 
public string Host = "";
/// 
/// The port number of the e-mail provider
/// 
public int Port = 25;
/// 
/// Does the e-mail body contain html content?
/// 
public bool Html = true;
/// 
/// Attenmpt to send the e-mail
/// 
/// True if succesfull, false if not. Any error will be put in the Error variable
public bool Send()
{
_error = "";
System.Net.Mail.SmtpClient smtpClient = new SmtpClient();
System.Net.Mail.MailMessage message = new MailMessage();
// validate
if (Host.Trim() == "") _error += "No host specified. ";
if (From.Trim() == "") _error += "No from e-mail specified. ";
if (To.Count + Cc.Count + Bcc.Count == 0) _error += "No to, cc or bcc e-mail address specified. ";
try
{
//host
smtpClient.Host = Host;
//default port 25
smtpClient.Port = Port;
//from address
message.From = new MailAddress(From, FromName);
//to addresses
foreach (string t in To) message.To.Add(t);
// cc addresses
foreach (string c in Cc) message.CC.Add(c);
// bcc addresses
foreach (string b in Bcc) message.Bcc.Add(b);
message.Subject = Subject;
//body html of niet
message.IsBodyHtml = Html;
//body text
message.Body = Body;
//send mail
smtpClient.Send(message);
}
catch (Exception ex)
{
_error += ex.ToString();
return false;
}
return true;
}
private string _error;
/// 
/// Contains the error message in case the e-mail was not sent.
/// 
public string Error
{
get { return _error; }
}
}
}

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!