-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserControlMailProperties.cs
129 lines (111 loc) · 4.46 KB
/
UserControlMailProperties.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace eMail
{
public partial class UserControlMailProperties : UserControl
{
public MailProperties MailProperties
{
get
{
if (mailProperties == null)
mailProperties = new global::eMail.MailProperties();
if (textBoxSender.Text == "")
mailProperties.SenderAddress = null;
else
mailProperties.SenderAddress = textBoxSender.Text;
if (textBoxUserName.Text == "")
mailProperties.SenderUserName = null;
else
mailProperties.SenderUserName = textBoxUserName.Text;
if (textBoxUserPassword.Text == "")
mailProperties.SenderPassword = null;
else
mailProperties.SenderPassword = MailProperties.SimpleEncode(textBoxUserPassword.Text);
mailProperties.SMTPclient = textBoxSMTPserver.Text;
mailProperties.SMTPclientPort = (int)numericUpDownPort.Value;
mailProperties.EnableSsl = checkBoxSSL.Checked;
mailProperties.RecipientAdresses = userControlMailAdresses.Addresses;
if (mailProperties.SenderAddress == null || mailProperties.SMTPclient == null || mailProperties.RecipientAdresses == null)
mailProperties = null;
return mailProperties;
}
set
{
mailProperties = value;
setProperties();
}
}
internal MailProperties mailProperties = null;
public bool ValidProperites
{
get
{
if (mailProperties != null)
{
if (!MailProperties.IsMailAddress(textBoxSender.Text))
return false;
if (textBoxSMTPserver.Text == "")
return false;
if (mailProperties.RecipientAdresses.Length > 0)
{
foreach (string s in mailProperties.RecipientAdresses)
if (!MailProperties.IsMailAddress(s))
return false;
}
else
return false;
return true;
}
else
return false;
}
set { }
}
public UserControlMailProperties()
{
InitializeComponent();
}
private void checkBoxShowPassword_CheckedChanged(object sender, EventArgs e)
{
if (!checkBoxShowPassword.Checked)
textBoxUserPassword.PasswordChar = '*';
else
textBoxUserPassword.PasswordChar = '\0';
textBoxUserPassword.Focus();
}
private void setProperties()
{
if (mailProperties != null)
{
textBoxSender.Text = mailProperties.SenderAddress;
textBoxUserName.Text = mailProperties.SenderUserName;
textBoxUserPassword.Text = mailProperties.SenderPassword;
textBoxSMTPserver.Text = mailProperties.SMTPclient;
numericUpDownPort.Value = (decimal)mailProperties.SMTPclientPort;
checkBoxSSL.Checked = mailProperties.EnableSsl;
userControlMailAdresses.Addresses = mailProperties.RecipientAdresses;
}
userControlMailAdresses.fillPanelRecipents();
}
private void textBoxSender_TextChanged(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
if (MailProperties.IsMailAddress(tb.Text))
tb.ForeColor = SystemColors.WindowText;
else
tb.ForeColor = Color.Red;
}
private void buttonSendTestMail_Click(object sender, EventArgs e)
{
if(eMail.Send(mailProperties,"Notification test", "Test Mesasge!",true))
MessageBox.Show("Mail is delivered!","Mail notification test", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}