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.Net;

/// <summary>
/// Wysyłanie e-maili
/// </summary>
public class SendMail
{
	public SendMail()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public void Wyslij(string nadawca, string adresat, string temat, string tresc)
    {

        //Tworzymy wiadomość email

        MailMessage wiadomosc = new MailMessage(nadawca, adresat, temat, tresc);

        //Ustawiamy format wiadomości jako HTML

        wiadomosc.IsBodyHtml = true;

        try
        {

            //Tworzymy klienta SMTP

            SmtpClient klientSMTP = new SmtpClient();

            //Ustwaiamy nazwę serwera SMTP

            klientSMTP.Host = "poczta.ct.com.pl";            

            //Ustawiamy sposób dostarczania wiadomości

            klientSMTP.DeliveryMethod = SmtpDeliveryMethod.Network;            
            NetworkCredential oCredential = new NetworkCredential("grzesiek@ct.com.pl", "sylw1a");
            klientSMTP.UseDefaultCredentials = false;
            klientSMTP.Credentials = oCredential;
            //Wysyłamy wiadomość przechwytując wyjątek

            klientSMTP.Send(wiadomosc);

        }

        catch (SmtpException ex)
        {

            throw new ApplicationException("Klient SMTP wywołał wyjątek " + ex.Message);

        }

        catch (Exception ex)
        {

            throw ex;

        }

    } 
}
