-
Notifications
You must be signed in to change notification settings - Fork 0
/
Campaigner.au3
1412 lines (942 loc) · 42.3 KB
/
Campaigner.au3
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.14.2
Author: George Roubis ([email protected])
Script Function:
A simple tool to deploy email campaigns.
#ce ----------------------------------------------------------------------------
#include <File.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <ComboConstants.au3>
#include <GuiDateTimePicker.au3>
#include <GuiListView.au3>
#include <FileConstants.au3>
#include "_IsValidEmail.au3"
#include "_INetSmtpMailCom.au3"
#include <GuiEdit.au3>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Check ini file ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Declare the ini file with default values
$INI_File = @ScriptDir&'\Campaigner.ini'
;If the ini file was not found
If FileExists($INI_File) = 0 Then
MsgBox(4096, "Ini file error", "Ini file '"&$INI_File&"' was not found.", 10)
Exit
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Declare global variables ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$MailServer = ''
$MailPort = ''
$MailSSL = 0
$AccountUsername = ''
$AccountPassword = ''
$FromName = ''
$FromAddress = ''
$Importance = ''
$HTMLTemplate = ''
$MandatoryHeaderElements = 2
$ToAddressColumnNumber = 0
$SubjectColumnNumber = 0
$FULL_LOG_RESULTS = ""
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Declare ini file predeclared variables of Server ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Read all Server section elements to an array
Local $INI_Server_Array = IniReadSection($INI_File, "MailServer")
;If an error occured
If @error Then
MsgBox(4096, "Ini file error", "Error while reading MailServer section from file '"&$INI_File&"'.", 10)
Exit
;If the section was succesfully read
Else
;Loop through all Server elements
For $i = 1 To $INI_Server_Array[0][0]
;Dynamically assign a variable
Assign($INI_Server_Array[$i][0], $INI_Server_Array[$i][1], 2)
Next
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Declare ini file predeclared variables of Mail ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Read all Mail section elements to an array
Local $INI_Mail_Array = IniReadSection($INI_File, "MailDefaults")
;If an error occured
If @error Then
MsgBox(4096, "Ini file error", "Error while reading MailDefaults section from file '"&$INI_File&"'.", 10)
Exit
;If the section was succesfully read
Else
;Loop through all mail elements
For $i = 1 To $INI_Mail_Array[0][0]
;Dynamically assign a variable
Assign($INI_Mail_Array[$i][0], $INI_Mail_Array[$i][1], 2)
Next
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Process INI variables ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;If ssl is off
If $MailSSL = 0 Then
$HumanReadableMailSSL = 'No'
;If SSL is on
Else
$HumanReadableMailSSL = 'Yes'
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Create the GUI ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Create the GUI
$CampaignerGUI = GUICreate ("Campaigner", 990 , 450)
;Set status to visible
GUISetState(@SW_SHOW)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Create the group with mail server configuration elements
GUICtrlCreateGroup("Mail Server Configuration", 10, 10, 480, 150)
;Create label and input for mail server ip/hostname
GUICtrlCreateLabel("Server Name/Ip Address", 25, 30, 160, 20)
$MailServerInput = GUICtrlCreateInput ( $MailServer, 150, 25 , 325 , 20)
;Create label and input for mail server port
GUICtrlCreateLabel("Server Port", 25, 53, 160, 20)
$MailPortInput = GUICtrlCreateInput ( $MailPort, 150, 50 , 230 , 20,$ES_NUMBER)
;Create a telnet button
$TelnetTestButton = GUICtrlCreateButton("Telnet", 390, 48, 85, 23)
;Create label and input for mail SSL mode
GUICtrlCreateLabel("Server SSL", 25, 80, 120, 20)
$MailSSLInput = GUICtrlCreateCombo ('', 151, 75, 70, 20,$CBS_DROPDOWNLIST )
GUICtrlSetData($MailSSLInput, "Yes|No", $HumanReadableMailSSL)
;Create label and input for mail username
GUICtrlCreateLabel("Account Username", 25, 105, 160, 20)
$MailAcountUsernameInput = GUICtrlCreateInput ( $AccountUsername, 150, 102 , 325 , 20)
;Create label and input for mail password
GUICtrlCreateLabel("Account Password", 25, 130, 160, 20)
$MailAcountPasswordInput = GUICtrlCreateInput ( $AccountPassword, 150, 127 , 325 , 20, $ES_PASSWORD)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Create the group with mail content configuration elements
GUICtrlCreateGroup("Mail Content Configuration", 10, 170, 480, 230)
;Create label and input for From Name
GUICtrlCreateLabel("From Name", 25, 194, 160, 20)
$FromNameInput = GUICtrlCreateInput ( $FromName, 150, 190 , 325 , 20)
;Create label and input for From address
GUICtrlCreateLabel("From Address", 25, 219, 160, 20)
$FromAddressInput = GUICtrlCreateInput ( $FromAddress, 150, 215 , 325 , 20)
;Create label and input for mail importance
GUICtrlCreateLabel("Mail Importance", 25, 245, 120, 20)
$MailImportanceInput = GUICtrlCreateCombo ('', 151, 241, 70, 20,$CBS_DROPDOWNLIST )
GUICtrlSetData($MailImportanceInput, "High|Normal|Low", $Importance)
;Create template file input label, input and button
GUICtrlCreateLabel("Template File", 25, 270, 100, 20)
$HTMLTemplateInput = GUICtrlCreateInput ( $HTMLTemplate, 150, 267 , 260 , 20 , $ES_READONLY)
$HTMLTemplateButton = GUICtrlCreateButton ( "Select", 416, 267, 60, 20)
;Create template file input label, input and button
GUICtrlCreateLabel("Data File", 25, 295, 100, 20)
$DataFileInput = GUICtrlCreateInput ( "", 150, 293 , 260 , 20 , $ES_READONLY)
$DataFileButton = GUICtrlCreateButton ( "Select", 416, 293, 60, 20)
;Create template file input label, input and button
GUICtrlCreateLabel("Attachment(s) (optional)", 25, 320, 120, 20)
$AttachmentFileInput = GUICtrlCreateInput ( "", 150, 319 , 130 , 20 , $ES_READONLY)
$AttachmentShowButton = GUICtrlCreateButton ( "Show", 286, 319, 60, 20)
$AttachmentDeleteButton = GUICtrlCreateButton ( "Delete", 351, 319, 60, 20)
$AttachmentFileButton = GUICtrlCreateButton ( "Select", 416, 319, 60, 20)
;Create CC input label and input
GUICtrlCreateLabel("CC (optional)", 25, 345, 100, 20)
$CCInput = GUICtrlCreateInput ( "", 150, 345 , 325 , 20)
;Create BCC input label and input
GUICtrlCreateLabel("BCC (optional)", 25, 371, 100, 20)
$BCCInput = GUICtrlCreateInput ( "", 150, 371 , 325 , 20)
;Create operation buttons
$ExitButton = GUICtrlCreateButton("Exit", 106, 410, 85, 25)
$UnlockUIButton = GUICtrlCreateButton("Unlock", 206, 410, 85, 25)
$CheckButton = GUICtrlCreateButton("Check", 306, 410, 85, 25)
$RunButton = GUICtrlCreateButton("Launch", 406, 410, 85, 25)
;Pre-disable the run button
GUICtrlSetState ( $RunButton, $GUI_DISABLE )
;Pre-disable the unlock button
GUICtrlSetState ( $UnlockUIButton, $GUI_DISABLE )
;Create the group with preview listview
GUICtrlCreateGroup("Campaign Preview", 500, 10, 480, 390)
;Create the list view structure
$PreviewerListview = GUICtrlCreateListView("Recipient|Subject|Status", 510, 25, 460, 340)
;Set list view column widths
_GUICtrlListView_SetColumnWidth ( $PreviewerListview, 0, 150 )
_GUICtrlListView_SetColumnWidth ( $PreviewerListview, 1, 240 )
;Create the log preview button
$LogPreviewButton = GUICtrlCreateButton("View Log", 796, 410, 85, 25)
;Pre-disable the log preview button
GUICtrlSetState ( $LogPreviewButton, $GUI_DISABLE )
;Create the html preview button
$HTMLPreviewButton = GUICtrlCreateButton("Preview", 896, 410, 85, 25)
;Pre-disable the preview button
GUICtrlSetState ( $HTMLPreviewButton, $GUI_DISABLE)
;Create a label for
$TotalCampaignMailsCounter = GUICtrlCreateLabel("", 771, 380, 200, 20, $SS_RIGHT )
;Set color to transparent
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Start GUI operation ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Run the GUI until the dialog is closed
While 1
;Get current action
$msg = GUIGetMsg()
;Handle changes
Select
;If X was pressed
Case $msg = $GUI_EVENT_CLOSE
;Exit
ExitLoop
;If Exit was pressed
Case $msg = $ExitButton
;Exit
ExitLoop
;If Telnet button was pressed
Case $msg = $TelnetTestButton
;Get server
$TelnetHost = GUICtrlRead($MailServerInput)
;Get port
$TelnetPort = GUICtrlRead($MailPortInput)
$GlobalTelnetErrorText = ''
$TelnetErrorStatus = 0
;If SMTP mail server is blank
If StringStripWS($TelnetHost,8) = '' Then
;Update the error
$GlobalTelnetErrorText &= "Server Name/Ip Address can not be blank."&@CRLF
;ExitLoop
$TelnetErrorStatus+=1
EndIf
;If SMTP mail server port is blank
If StringStripWS($TelnetPort,8) = '' Then
;Update the error
$GlobalTelnetErrorText &= "Server port can not be blank."&@CRLF
;ExitLoop
$TelnetErrorStatus+=1
EndIf
;If an error was found
If $TelnetErrorStatus > 0 Then
;Notify
MsgBox(4096, "Error", $TelnetErrorStatus&" error(s) identified:"&@CRLF&$GlobalTelnetErrorText, 0, $CampaignerGUI)
Else
;If file exists
If (FileExists ( @SCRIPTDIR&"\telnet\telnet.exe" ) = 1) Then
;Launch telnet
Run(@SCRIPTDIR&"\telnet\telnet.exe "&$TelnetHost&" "&$TelnetPort)
Else
;Notify
MsgBox(4096, "Error", "File "&@ScriptDir&"\telnet\telnet.exe not found!", 0, $CampaignerGUI)
EndIf
EndIf
;If the HTML template file selection button was clicked
Case $msg = $HTMLTemplateButton
;Open the file selection dialog
Dim $HTMLTemplate = FileOpenDialog ( "HTML Template Selection", @ScriptDir, "HTML files (*.html;*.htm)" ,$FD_FILEMUSTEXIST + $FD_PATHMUSTEXIST, "", $CampaignerGUI)
;If an error occured
If @error Then
Else
;Update the file input box
GUICtrlSetData($HTMLTemplateInput, $HTMLTemplate)
EndIf
;If the Data file selection button was clicked
Case $msg = $DataFileButton
;Open the file selection dialog
Dim $DataFile = FileOpenDialog ( "Data File Selection", @ScriptDir, "Data files (*.csv;*.txt)" ,$FD_FILEMUSTEXIST + $FD_PATHMUSTEXIST, "", $CampaignerGUI)
;If an error occured
If @error Then
Else
;Update the file input box
GUICtrlSetData($DataFileInput, $DataFile)
EndIf
Case $msg = $CheckButton
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Disable GUI elements ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Lock UI elements to avoid changes or errors
GUICtrlSetState ($MailServerInput, $GUI_DISABLE)
GUICtrlSetState ($MailPortInput, $GUI_DISABLE)
GUICtrlSetState ($MailSSLInput, $GUI_DISABLE)
GUICtrlSetState ($MailSSLInput, $GUI_DISABLE)
GUICtrlSetState ($MailAcountUsernameInput, $GUI_DISABLE)
GUICtrlSetState ($MailAcountPasswordInput, $GUI_DISABLE)
GUICtrlSetState ($FromNameInput, $GUI_DISABLE)
GUICtrlSetState ($FromAddressInput, $GUI_DISABLE)
GUICtrlSetState ($MailImportanceInput, $GUI_DISABLE)
GUICtrlSetState ($DataFileButton, $GUI_DISABLE)
GUICtrlSetState ($HTMLTemplateButton, $GUI_DISABLE)
GUICtrlSetState ($CheckButton, $GUI_DISABLE)
GUICtrlSetState ($AttachmentDeleteButton, $GUI_DISABLE)
GUICtrlSetState ($AttachmentShowButton, $GUI_DISABLE)
GUICtrlSetState ($AttachmentFileButton, $GUI_DISABLE)
GUICtrlSetState ($CCInput, $GUI_DISABLE)
GUICtrlSetState ($BCCInput, $GUI_DISABLE)
GUICtrlSetState ($ExitButton, $GUI_DISABLE)
GUICtrlSetState ($TelnetTestButton, $GUI_DISABLE)
;disable unlock button
GUICtrlSetState ( $UnlockUIButton, $GUI_DISABLE)
;Update the counter label
GUICtrlSetData ($TotalCampaignMailsCounter, 'Checking Data...')
;Clear the listview
_GUICtrlListView_DeleteAllItems($PreviewerListview)
;Disable the preview button
GUICtrlSetState ( $HTMLPreviewButton, $GUI_DISABLE)
;Disable the launch button
GUICtrlSetState ($RunButton, $GUI_DISABLE)
;Declare an operation error handler
$CheckComplete = 0
$ErrorStatus = 0
;Reset arrays and strings
Dim $RawDataArray
Dim $TemplateFileRead = ''
;If no error was detected
While $CheckComplete = 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Get GUI data ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Update the counter label
GUICtrlSetData ($TotalCampaignMailsCounter, 'Checking Mail Server configuration.')
;Get Mail Server
$SMTPMailServer = GUICtrlRead($MailServerInput)
;Get Mail Port
$SMTPPort = GUICtrlRead($MailPortInput)
;Get SSL mode and convert it to boolean
If GUICtrlRead($MailSSLInput) = 'Yes' Then
$SMTPSSL = 1
Else
$SMTPSSL = 0
EndIf
;Get SMTP Account Username
$SMTPAccountUsername = GUICtrlRead($MailAcountUsernameInput)
;Get SMTP Account Password
$SMTPAccountPassword = GUICtrlRead($MailAcountPasswordInput)
;Update the counter label
GUICtrlSetData ($TotalCampaignMailsCounter, 'Checking Mail Content configuration.')
;Get SMTP From Name
$SMTPFromName = GUICtrlRead($FromNameInput)
;Get SMTP From Address
$SMTPFromAddress = GUICtrlRead($FromAddressInput)
;Get SMTP importance
$SMTPImportance = GUICtrlRead($MailImportanceInput)
;Get SMTP Template file
$SMTPTemplateFile = GUICtrlRead($HTMLTemplateInput)
;Get SMTP Data file
$SMTPDataFile = GUICtrlRead($DataFileInput)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Validate Data ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$GlobalErrorText = ''
;If SMTP mail server is blank
If StringStripWS($SMTPMailServer,8) = '' Then
;Update the error
$GlobalErrorText &= "Server Name/Ip Address can not be blank."&@CRLF
;ExitLoop
$ErrorStatus+=1
EndIf
;If SMTP mail server port is blank
If StringStripWS($SMTPPort,8) = '' Then
;Update the error
$GlobalErrorText &= "Server port can not be blank."&@CRLF
;ExitLoop
$ErrorStatus+=1
EndIf
#cs
;If SMTP account username is blank
If StringStripWS($SMTPAccountUsername,8) = '' Then
;Update the error
$GlobalErrorText &= "Server account username can not be blank."&@CRLF
;ExitLoop
$ErrorStatus+=1
EndIf
;If SMTP account password is blank
If StringStripWS($SMTPAccountPassword,8) = '' Then
;Update the error
$GlobalErrorText &= "Server account password can not be blank."&@CRLF
;ExitLoop
$ErrorStatus+=1
EndIf
#ce
;If From name is blank
If StringStripWS($SMTPFromName,8) = '' Then
;Update the error
$GlobalErrorText &= "From name can not be blank."&@CRLF
;ExitLoop
$ErrorStatus+=1
EndIf
;If From address is invalid
If _IsValidEmail($SMTPFromAddress) = 0 Then
;Update the error
$GlobalErrorText &= "From address is invalid."&@CRLF
;ExitLoop
$ErrorStatus+=1
EndIf
;Open the template file
Local $TemplateFileOpen = FileOpen($SMTPTemplateFile, $FO_READ)
;If unable to open
If $TemplateFileOpen = -1 Then
;Update the error
$GlobalErrorText &= "Unable to open template file for reading."&@CRLF
;ExitLoop
$ErrorStatus+=1
;If file was opened, read data
Else
;Read the file
$TemplateFileRead = FileRead($TemplateFileOpen)
If @error = 1 Then
;Update the error
$GlobalErrorText &= "Unable to read data from template file."&@CRLF
;ExitLoop
$ErrorStatus+=1
Else
;close the file
FileClose($TemplateFileOpen)
EndIf
EndIf
;If file contents are blank
If $TemplateFileRead = '' Then
;Update the error
$GlobalErrorText &= "Template file is empty."&@CRLF
;ExitLoop
$ErrorStatus+=1
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Check attachments ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Get attachments string
$SMTPAttachments = GUICtrlRead($AttachmentFileInput)
;If the string is empty
If StringStripWS($SMTPAttachments,8) = '' Then
$MailAttachments = ''
;Else
Else
;Convert string to array
$TempAttachmentsRawArray = StringSplit($SMTPAttachments,'|')
If @error = 1 then
Dim $TempAttachmentsFPArray[2] = [1,$SMTPAttachments]
Else
;Get the attachments directory
$TempAttachmentsPath = $TempAttachmentsRawArray[1]
;Declare an path to store all attachments with their full path
Dim $TempAttachmentsFPArray[1] = [0]
;Loop through all attachments to get full paths
For $i = 2 To $TempAttachmentsRawArray[0]
;Add element
_ArrayAdd($TempAttachmentsFPArray,$TempAttachmentsPath&'\'&$TempAttachmentsRawArray[$i])
;Increase index
$TempAttachmentsFPArray[0]+=1
Next
EndIf
;Loop through all attachments and attempt to open them
For $i = 1 To $TempAttachmentsFPArray[0]
;Open the attachment file
Local $CurrentAttachmentOpen = FileOpen($TempAttachmentsFPArray[$i], $FO_READ)
;If unable to open
If $CurrentAttachmentOpen = -1 Then
;Update the error
$GlobalErrorText &= 'Unable to open attachment file "'&$TempAttachmentsFPArray[$i]&'".'&@CRLF
;ExitLoop
$ErrorStatus+=1
;If file was opened, read data
Else
FileClose($CurrentAttachmentOpen)
EndIf
Next
;Convert the attachments string to valid email ready string
$MailAttachments = _ArrayToString($TempAttachmentsFPArray,';',1,$TempAttachmentsFPArray[0])
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Check CC address ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Get SMTP CC address
$SMTPCCAddress = StringStripWS(GUICtrlRead($CCInput),8)
;Convert address to array
$SMTPCCAddressArray = StringSplit($SMTPCCAddress,';')
;Check if blank
If _ArrayToString($SMTPCCAddressArray,'',1) <> '' Then
;Loop through addresses
For $i = 1 To $SMTPCCAddressArray[0]
;If CC address is invalid
If _IsValidEmail($SMTPCCAddressArray[$i]) = 0 Then
;Update the error
$GlobalErrorText &= 'CC address "'&$SMTPCCAddressArray[$i]&'" is invalid.'&@CRLF
;ExitLoop
$ErrorStatus+=1
ExitLoop
EndIf
Next
EndIf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Check BCC address ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Get SMTP CC address
$SMTPBCCAddress = StringStripWS(GUICtrlRead($BCCInput),8)
;Convert address to array
$SMTPBCCAddressArray = StringSplit($SMTPBCCAddress,';')
;Check if blank
If _ArrayToString($SMTPBCCAddressArray,'',1) <> '' Then
;Loop through addresses
For $i = 1 To $SMTPBCCAddressArray[0]
;If CC address is invalid
If _IsValidEmail($SMTPBCCAddressArray[$i]) = 0 Then
;Update the error
$GlobalErrorText &= 'BCC address "'&$SMTPBCCAddressArray[$i]&'" is invalid.'&@CRLF
;ExitLoop
$ErrorStatus+=1
ExitLoop
EndIf
Next
EndIf
;Read the data file to an array
_FileReadToArray ( $SMTPDataFile, $RawDataArray, 1 )
;If an error occured
If @error Then
;1 - Error opening specified file
If @error = 1 Then
;Update the error
$GlobalErrorText &= "Unable to open data file for reading."&@CRLF
;ExitLoop
$ErrorStatus+=1
;2 - Unable to Split the file
ElseIf @error = 2 Then
;Update the error
$GlobalErrorText &= "Unable to convert data file to a memory array (spliting issue)."&@CRLF
;ExitLoop
$ErrorStatus+=1
EndIf
Else
;Check for blank file
If StringLen(StringStripWS(_ArrayToString($RawDataArray,"",1),8)) = 0 Then
;Update the error
$GlobalErrorText &= "Data file is empty."&@CRLF
;ExitLoop
$ErrorStatus+=1
;If not blank check data
Else
;Loop through lines to check data
For $i = 1 To $RawDataArray[0]
;Convert the line to an array
$CurrentLineArray = StringSplit($RawDataArray[$i],';')
;If the length is at least 2
If $CurrentLineArray[0] <= 2 Then
;Update the error
$GlobalErrorText &= "Line "&$i&" contains less than 3 data columns."&@CRLF
;ExitLoop
$ErrorStatus+=1
ExitLoop
Else
EndIf
Next
EndIf
EndIf
;If no error
If $ErrorStatus = 0 Then
;Get Headers
$HeaderLineArray = StringSplit($RawDataArray[1],';')
;Set a variable to compare with mandatory elements
$ToAddressHeadersFound = 0
$SubjectHeadersFound = 0
;Declare an array to store replacement rules
Dim $ReplaceRulesArray[1][2]=[["ColumnName", "ColumnPosition"]]
;Loop through headers
For $i = 1 To $HeaderLineArray[0]
;If a mandatory column was found
If $HeaderLineArray[$i] = 'ToAddress' Then
;Increase the counter
$ToAddressHeadersFound+=1
;Update the column position
$ToAddressColumnNumber = $i
EndIf
Next
;Loop through headers
For $i = 1 To $HeaderLineArray[0]
;If a mandatory column was found
If $HeaderLineArray[$i] = 'Subject' Then
;Increase the counter
$SubjectHeadersFound+=1
;Update the column position
$SubjectColumnNumber = $i
EndIf
Next
;Check if everything is fine
If $ToAddressHeadersFound = 1 And $SubjectHeadersFound = 1 Then
;Loop through headers
For $i = 1 To $HeaderLineArray[0]
;If a dynamic column was matched
If $HeaderLineArray[$i] <> 'Subject' And $HeaderLineArray[$i] <> 'ToAddress' Then
;Increase lengths
ReDim $ReplaceRulesArray[Ubound($ReplaceRulesArray)+1][2]
;Update rules
$ReplaceRulesArray[Ubound($ReplaceRulesArray)-1][0] = "[{"&$HeaderLineArray[$i]&"}]"
$ReplaceRulesArray[Ubound($ReplaceRulesArray)-1][1] = $i
EndIf
Next
;If a header was missing
Else
;Update the error
$GlobalErrorText &= "Data file does not contain all mandatory columns."&@CRLF
;ExitLoop
$ErrorStatus+=1
EndIf
EndIf
;If no error
If $ErrorStatus = 0 Then
Dim $ReadyToEmailArray[1][3]=[["To Address", "Subject", "HTML Content"]]
;Loop through data
For $i = 2 To $RawDataArray[0]
;Update the counter label
GUICtrlSetData ($TotalCampaignMailsCounter, 'Generating dynamic email '&$i&' of '&$RawDataArray[0]&'.')
;Convert the line to an array
$CurrentLine = StringSplit($RawDataArray[$i],';')
$CurrentHTMLString = $TemplateFileRead
;Increase lengths
ReDim $ReadyToEmailArray[Ubound($ReadyToEmailArray)+1][3]
;Loop through line elements
For $y = 1 To $CurrentLine[0]
;If To was found
If $y = $ToAddressColumnNumber Then
$ReadyToEmailArray[Ubound($ReadyToEmailArray)-1][0] = $CurrentLine[$y]
;If Subject was found
ElseIf $y = $SubjectColumnNumber Then
$ReadyToEmailArray[Ubound($ReadyToEmailArray)-1][1] = $CurrentLine[$y]
;If another column was matched
Else
;Loop through rules
For $j = 1 To Ubound($ReplaceRulesArray)-1
;If a rule was matched
If $ReplaceRulesArray[$j][1] = $y then
;Replace the keyword
$CurrentHTMLString = StringReplace($CurrentHTMLString,$ReplaceRulesArray[$j][0],$CurrentLine[$y])
;Update the array
$ReadyToEmailArray[Ubound($ReadyToEmailArray)-1][2] = $CurrentHTMLString
EndIf
Next
EndIf
Next
Next
EndIf
;If no error - check for invalid emails
If $ErrorStatus = 0 Then
For $i = 1 To Ubound($ReadyToEmailArray)-1
;Update the counter label
GUICtrlSetData ($TotalCampaignMailsCounter, 'Checking recipient '&$i&' of '&(Ubound($ReadyToEmailArray)-1)&'.')
If _IsValidEmail($ReadyToEmailArray[$i][0]) = 0 Then
;Update the error
$GlobalErrorText &= "Line "&($i+1)&" contains an invalid email recipient("&$ReadyToEmailArray[$i][0]&")."&@CRLF
;ExitLoop
$ErrorStatus+=1
EndIf
Next
EndIf
;If no error - update list view
If $ErrorStatus = 0 Then
$TotalOutgoing = 0
;Update list view elements
For $i = 1 To Ubound($ReadyToEmailArray) -1
;Update the counter label
GUICtrlSetData ($TotalCampaignMailsCounter, 'Updating preview element '&$i&' of '&(Ubound($ReadyToEmailArray) -1)&'.')
GUICtrlCreateListViewItem($ReadyToEmailArray[$i][0]&"|"&$ReadyToEmailArray[$i][1], $PreviewerListview)
$TotalOutgoing+=1
Next
;enable the preview button
GUICtrlSetState ($HTMLPreviewButton, $GUI_ENABLE)
;enable the launch button
GUICtrlSetState ($RunButton, $GUI_ENABLE)
;Update the counter label
GUICtrlSetData ($TotalCampaignMailsCounter, 'Total emails in campaign: '& $TotalOutgoing)
;Lock UI elements to avoid changes or errors
GUICtrlSetState ($MailServerInput, $GUI_DISABLE)
GUICtrlSetState ($MailPortInput, $GUI_DISABLE)
GUICtrlSetState ($MailSSLInput, $GUI_DISABLE)
GUICtrlSetState ($MailSSLInput, $GUI_DISABLE)
GUICtrlSetState ($MailAcountUsernameInput, $GUI_DISABLE)
GUICtrlSetState ($MailAcountPasswordInput, $GUI_DISABLE)
GUICtrlSetState ($FromNameInput, $GUI_DISABLE)
GUICtrlSetState ($FromAddressInput, $GUI_DISABLE)
GUICtrlSetState ($MailImportanceInput, $GUI_DISABLE)
GUICtrlSetState ($DataFileButton, $GUI_DISABLE)
GUICtrlSetState ($HTMLTemplateButton, $GUI_DISABLE)
GUICtrlSetState ($CheckButton, $GUI_DISABLE)
GUICtrlSetState ($AttachmentDeleteButton, $GUI_DISABLE)
GUICtrlSetState ($AttachmentShowButton, $GUI_DISABLE)
GUICtrlSetState ($AttachmentFileButton, $GUI_DISABLE)
GUICtrlSetState ($CCInput, $GUI_DISABLE)
GUICtrlSetState ($BCCInput, $GUI_DISABLE)
GUICtrlSetState ($TelnetTestButton, $GUI_DISABLE)
;enablethe unlock button