And here goes. I started by writing a custom exception for my C# Smtp class. Whenever my C# class encounters faults, I'll throw an instance of this exception.
public class SmtpException : System.Exception
{
private string message;
public SmtpException( string str)
{
message = str;
}
public string What()
{
return message;
}
};
Our class will be inherited from the System.Net.Socket.TcpClient
class
in the dotNET framework. This class provides all the base functionality that
is required to do TCP/ IP programming. Our class declaration is presented below.
public class Smtp : System.Net.Sockets.TcpClient
Our class will have eight data members. The from data member is the sender of the email. The to, cc and bcc data members represent the recipients of the email. The subject data member is the subject of the email. Either bodyText or bodyHtml will represent the body of the email. The server data member represents the SMTP server where our client is sending the message. Here are the data member definitions.
public class Smtp : System. Net. Sockets. TcpClient
{
public string from = null;
public ArrayList to;
public ArrayList cc;
public ArrayList bcc;
public string subject = null;
public string bodyText = null;
public string bodyHtml = null;
public string server = null;
The to, cc and bcc data members are arrays, in order to allow multiple recipients of all three types. All three arrays must be created in the constructor of our class.
public Smtp()
{
to = new ArrayList();
cc = new ArrayList();
bcc = new ArrayList();
}
Comments