DotNetOpenMail Send e-mail class

DotNetOpenMail sınıfı ile asp.net ve c# windows formlar üzerinden mail göndermek için pratik bir code classı olusturdum..

public class EmailTools
{
    private string smtpServerAdress = "mail.mailserver.com";
    private string loginName = "eravse@eravse.com";
    private string loginPassword = "password";
    private string gonderenEmailAdress = "eravse@eravse.com";
    private string gonderenAd = "Webmaster";
    private string aliciEmailAdress = string.Empty;
    private string htmlBody = string.Empty;
    private string subject = string.Empty;

    public string SmtpServerAdress
    {
        get
        {
            return smtpServerAdress;
        }
        set
        {
            smtpServerAdress = value;
        }
    }
    public string LoginName
    {
        get
        {
            return loginName;
        }
        set
        {
            loginName = value;
        }
    }
    public string LoginPassword
    {
        get
        {
            return loginPassword;
        }
        set
        {
            loginPassword = value;
        }
    }
    public string GonderenEmailAdress
    {
        get
        {
            return gonderenEmailAdress;
        }
        set
        {
            gonderenEmailAdress = value;
        }
    }
    public string GonderenAd
    {
        get
        {
            return gonderenAd;
        }
        set
        {
            gonderenAd = value;
        }
    }
    public string AliciEmailAdress
    {
        get
        {
            return aliciEmailAdress;
        }
        set
        {
            aliciEmailAdress = value;
        }
    }
    public string HtmlBody
    {
        get
        {
            return htmlBody;
        }
        set
        {
            htmlBody = value;
        }
    }
    public string Subject
    {
        get
        {
            return subject;
        }
        set
        {
            subject = value;
        }
    }

    public string SendEmail()
    {
        try
        {
            SmtpServer istemci = new SmtpServer(SmtpServerAdress);
            LoginAuthToken login = new LoginAuthToken(LoginName, LoginPassword);

            istemci.SmtpAuthToken = login;

            EmailMessage mail = new EmailMessage();

            EmailAddress gonderen = new EmailAddress(GonderenEmailAdress, GonderenAd);

            EmailAddress alici = new EmailAddress(AliciEmailAdress);

              // Bcc ve CC eklemek ıcınde aynı yontem kullanılabılır 
            //EmailAddress bcc = new EmailAddress("");
           //EmailAddress cc = new EmailAddress("");

            mail.FromAddress = gonderen;
            mail.AddToAddress(alici);


            //mail.AddCcAddress(bcc);

            mail.Subject = Subject;

            mail.HtmlPart = new HtmlAttachment(HtmlBody);

            mail.Send(istemci);

            return "Mail Send";
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }
}

Yanıt Yaz