-
Notifications
You must be signed in to change notification settings - Fork 19
/
FormEmailServer.pas
154 lines (114 loc) · 4.23 KB
/
FormEmailServer.pas
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
UNIT FormEmailServer;
{-------------------------------------------------------------------------------------------------------------
2021.03.24
Universal 'email server settings' form
Used in: Power Email Extractor, PingMail, etc
-------------------------------------------------------------------------------------------------------------}
INTERFACE
{$DENYPACKAGEUNIT ON} {Prevents unit from being placed in a package. https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Packages_(Delphi)#Naming_packages }
{Hostinger: the max PHP emails per minute is 60 and your limit for emails per day is 3000 ? = 1 email at 24 sec }
USES
System.SysUtils, System.Classes, Vcl.Controls, Vcl.Forms, Vcl.StdCtrls, Vcl.Samples.Spin, Vcl.ExtCtrls,
IdSMTP, IdExplicitTLSClientServerBase, Vcl.ComCtrls, cvRadioButton, InternetLabel;
type
TfrmSmtpSettings = class(TForm)
btnGMailDef : TButton;
Button1 : TButton;
edtPsw : TLabeledEdit;
edtUserName : TLabeledEdit;
grpSettings : TGroupBox;
grpTSL : TGroupBox;
lblPort : TLabel;
ledHost : TLabeledEdit;
radTslExpl : TCubicRadioButton;
radTslImplic : TCubicRadioButton;
radTslNone : TCubicRadioButton;
radTslRequire : TCubicRadioButton;
spnPort : TSpinEdit;
inetAllowLessSecure: TInternetLabel;
procedure Button1Click (Sender: TObject);
procedure btnGMailDefClick (Sender: TObject);
procedure FormDestroy (Sender: TObject);
procedure FormCreate (Sender: TObject);
private
public
procedure UseExternalMailer(SMTP: TIdSMTP);
procedure UseInternalMailer(SMTP: TIdSMTP);
function IsValid(SMTP: TIdSMTP): Boolean;
procedure Initialize;
end;
VAR
frmSmtpSettings: TfrmSmtpSettings;
IMPLEMENTATION {$R *.dfm}
USES cmEncodeXOR, cvIniFile;
procedure TfrmSmtpSettings.FormCreate(Sender: TObject);
begin
// Let the main from call frmSettings.LoadIni
end;
procedure TfrmSmtpSettings.Initialize;
begin
LoadForm(Self);
edtPsw.Text:= SimpleDecode(edtPsw.Text); // automatically decrypt AFTER loading from INI
end;
procedure TfrmSmtpSettings.FormDestroy(Sender: TObject);
begin
edtPsw.Text:= Simpleencode(edtPsw.Text); // encrypt the password BEFORE saving to INI!
SaveForm(Self);
end;
CONST DemoEmail= 'smtp.Gmail.com';
function TfrmSmtpSettings.IsValid(SMTP: TIdSMTP): Boolean;
begin
Result:= (SMTP.UserName > '') AND
(SMTP.UserName <> DemoEmail) AND
(SMTP.Password > '') AND
(SMTP.Host > '') AND
(SMTP.Port > 0) AND
(radTslNone.Checked OR radTslImplic.Checked OR radTslExpl.Checked OR radTslRequire.Checked);
end;
{--------------------------------------------------------------------------------------------------
Apply SMTP server settings
--------------------------------------------------------------------------------------------------}
procedure TfrmSmtpSettings.UseExternalMailer(SMTP: TIdSMTP);
begin
Assert(SMTP <> NIL);
if SMTP.Connected
then SMTP.Disconnect;
if radTslNone.Checked
then SMTP.UseTLS:= utNoTLSSupport else
if radTslImplic.Checked
then SMTP.UseTLS:= utUseImplicitTLS else
if radTslExpl.Checked
then SMTP.UseTLS:= utUseExplicitTLS else
if radTslRequire.Checked
then SMTP.UseTLS:= utUseRequireTLS;
SMTP.Password:= edtPsw.Text;
SMTP.Username:= edtUserName.Text;
SMTP.Port := spnPort.Value;
SMTP.Host := ledHost.Text;
end;
procedure TfrmSmtpSettings.UseInternalMailer(SMTP: TIdSMTP);
begin
SMTP.UseTLS := utUseExplicitTLS;
SMTP.Password:= '';
SMTP.Username:= '[email protected]';
SMTP.Port := 587;
SMTP.Host := 'smtp.Gmail.com';
end;
procedure TfrmSmtpSettings.btnGMailDefClick(Sender: TObject);
begin
ledHost.Text := DemoEmail;
spnPort.Value := 587;
edtUserName.Text := '[email protected]';
radTslExpl.Checked:= TRUE;
inetAllowLessSecure.Visible:= TRUE;
end;
{--------------------------------------------------------------------------------------------------
OTHERS
--------------------------------------------------------------------------------------------------}
procedure TfrmSmtpSettings.Button1Click(Sender: TObject);
begin
if edtPsw.PasswordChar= #0
then edtPsw.PasswordChar:= '*'
else edtPsw.PasswordChar:= #0;
end;
end.