root/trunk/eCard/Expo/App_Code/SendMail.cs @ 477

Wersja 477, 1.6 KB (wprowadzona przez marek, 17 years temu)

re #139

Line 
1using System;
2using System.Data;
3using System.Configuration;
4using System.Web;
5using System.Web.Security;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8using System.Web.UI.WebControls.WebParts;
9using System.Web.UI.HtmlControls;
10using System.Net.Mail;
11using System.Net;
12
13/// <summary>
14/// Wysy³anie e-maili
15/// </summary>
16public class SendMail
17{
18        public SendMail()
19        {
20                //
21                // TODO: Add constructor logic here
22                //
23        }
24
25    public void Wyslij(string nadawca, string adresat, string temat, string tresc)
26    {
27
28        //Tworzymy wiadomoœæ email
29
30        MailMessage wiadomosc = new MailMessage(nadawca, adresat, temat, tresc);
31
32        //Ustawiamy format wiadomoœci jako HTML
33
34        wiadomosc.IsBodyHtml = true;
35
36        try
37        {
38
39            //Tworzymy klienta SMTP
40
41            SmtpClient klientSMTP = new SmtpClient();
42
43            //Ustwaiamy nazwê serwera SMTP
44
45            klientSMTP.Host = "smtp.ct.com.pl";           
46
47            //Ustawiamy sposób dostarczania wiadomoœci
48
49            //klientSMTP.DeliveryMethod = SmtpDeliveryMethod.Network;
50            NetworkCredential oCredential = new NetworkCredential(ConfigurationManager.AppSettings["SmtpUser"], ConfigurationManager.AppSettings["SmtpPwd"]);
51            //klientSMTP.UseDefaultCredentials = false;
52            //klientSMTP.Credentials = oCredential;
53            //Wysy³amy wiadomoœæ przechwytuj¹c wyj¹tek
54
55            klientSMTP.Send(wiadomosc);
56
57        }
58
59        catch (SmtpException ex)
60        {
61
62            throw new ApplicationException("Klient SMTP wywo³a³ wyj¹tek " + ex.Message);
63
64        }
65    }
66}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.