| Line | |
|---|
| 1 | using System;
|
|---|
| 2 | using System.Data;
|
|---|
| 3 | using System.Configuration;
|
|---|
| 4 | using System.Web;
|
|---|
| 5 | using System.Web.Security;
|
|---|
| 6 | using System.Web.UI;
|
|---|
| 7 | using System.Web.UI.WebControls;
|
|---|
| 8 | using System.Web.UI.WebControls.WebParts;
|
|---|
| 9 | using System.Web.UI.HtmlControls;
|
|---|
| 10 | using System.Net.Mail;
|
|---|
| 11 | using System.Net;
|
|---|
| 12 |
|
|---|
| 13 | /// <summary>
|
|---|
| 14 | /// Wysy³anie e-maili
|
|---|
| 15 | /// </summary>
|
|---|
| 16 | public 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 wiadomoci 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 wiadomoci
|
|---|
| 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.