| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.ComponentModel;
|
|---|
| 4 | using System.Data;
|
|---|
| 5 | using System.Drawing;
|
|---|
| 6 | using System.Text;
|
|---|
| 7 | using System.Windows.Forms;
|
|---|
| 8 | using System.Net;
|
|---|
| 9 | using System.Net.Mail;
|
|---|
| 10 | using System.Text.RegularExpressions;
|
|---|
| 11 | using System.IO;
|
|---|
| 12 | using BazaZamowien.Classes;
|
|---|
| 13 | using BazaZamowien.zamowieniaDataSetTableAdapters;
|
|---|
| 14 |
|
|---|
| 15 | namespace BazaZamowien
|
|---|
| 16 | {
|
|---|
| 17 | public partial class MailForm : Form
|
|---|
| 18 | {
|
|---|
| 19 |
|
|---|
| 20 | public MailForm()
|
|---|
| 21 | {
|
|---|
| 22 | InitializeComponent();
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | private void WylijButton_Click(object sender, EventArgs e)
|
|---|
| 26 | {
|
|---|
| 27 | //walidacja maili
|
|---|
| 28 |
|
|---|
| 29 | Regex r = new Regex("^[a-zA-Z0-9_\\.\\-]+@[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-\\.]+$");
|
|---|
| 30 |
|
|---|
| 31 | if (!r.IsMatch(odEmailTextBox.Text))
|
|---|
| 32 | {
|
|---|
| 33 | MessageBox.Show("Niepoprawny adres mailowy nadawcy");
|
|---|
| 34 | return;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | if (!r.IsMatch(doEmailTextBox.Text))
|
|---|
| 38 | {
|
|---|
| 39 | MessageBox.Show("Nieporawny adres mailowy odbiorcy");
|
|---|
| 40 | return;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | if (!r.IsMatch(doWiadomosciTextBox.Text))
|
|---|
| 44 | {
|
|---|
| 45 | MessageBox.Show("Nieporawny adres mailowy 'do wiadomoci'");
|
|---|
| 46 | return;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | this.Cursor = Cursors.WaitCursor;
|
|---|
| 50 |
|
|---|
| 51 | MailAddress adresOD = new MailAddress(odEmailTextBox.Text, odTextBox.Text);
|
|---|
| 52 | MailAddress adresDO = new MailAddress(doEmailTextBox.Text, doComboBox.Text);
|
|---|
| 53 | MailMessage message = new MailMessage(adresOD, adresDO);
|
|---|
| 54 |
|
|---|
| 55 | message.CC.Add(doWiadomosciTextBox.Text);
|
|---|
| 56 | message.Subject = tematTextBox.Text;
|
|---|
| 57 | message.Body = trescTextBox.Text;
|
|---|
| 58 |
|
|---|
| 59 | SmtpClient klientSMTP = new SmtpClient("poczta.ct.com.pl");
|
|---|
| 60 | klientSMTP.Timeout = 1000000;
|
|---|
| 61 | //klientSMTP.EnableSsl = false;
|
|---|
| 62 | //klientSMTP.Credentials = new System.Net.NetworkCredential(User.getUser().Email, User.getUser().Password);
|
|---|
| 63 | //MessageBox.Show(User.getUser().Email + User.getUser().Password);
|
|---|
| 64 |
|
|---|
| 65 | try
|
|---|
| 66 | {
|
|---|
| 67 | klientSMTP.Send(message);
|
|---|
| 68 | MessageBox.Show("Wiadomoæ zosta³a wys³ana");
|
|---|
| 69 | this.Close();
|
|---|
| 70 | }
|
|---|
| 71 | catch (Exception e2)
|
|---|
| 72 | {
|
|---|
| 73 | MessageBox.Show(e2.Message);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | this.Cursor = Cursors.Default;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | private void doComboBox_SelectedIndexChanged(object sender, EventArgs e)
|
|---|
| 80 | {
|
|---|
| 81 | if (doComboBox.SelectedItem != null)
|
|---|
| 82 | {
|
|---|
| 83 | doEmailTextBox.Text = ((BoundItem)doComboBox.SelectedItem).StringValue;
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | }
|
|---|
| 88 | } |
|---|