This repository was archived by the owner on Jul 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib_powershell.rpf
More file actions
139 lines (109 loc) · 4.5 KB
/
lib_powershell.rpf
File metadata and controls
139 lines (109 loc) · 4.5 KB
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
{
Module Name: LIB POWERSHELL
Description: VGL POWERSHELL LIBRARY
Purpose: Library to provide easy implementation of various powershell tasks
MODIFICATION HISTORY
====================
SM Reference Date Name Description Filename
----------- --------------- --------------- --------------- ----------------------------------------------------------------------- -------------------
10.2 1.0 07-Oct-2014 B. vd Basch Created lib_powershell.rpf
10.2 1.1 23-Mar-2015 B. vd Basch Changed check mechanism and added HTML support lib_powershell.rpf
}
{Display, Libraries and Constants
====================================}
SET NAME "/DEFER"
SET COMPILE_OPTION DECLARE
ENABLE WINDOWS
JOIN LIBRARY $LIB_UTILS
JOIN STANDARD_LIBRARY STD_PROMPT
GLOBAL CONSTANT POWERSHELL = " C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "
DECLARE from_mail, to_mail, subject_line, mail_body
DECLARE smtp_server, smtp_port, smtp_user, smtp_password
DECLARE attachments
{ Dependencies check
====================================}
GLOBAL ROUTINE CHECK_POWERSHELL(VALUE POWERSHELL_PRESENT)
IF (FILE EXISTS(STRIP(POWERSHELL))) THEN
RETURN(TRUE)
ELSE
RETURN(FALSE)
ENDIF
ENDROUTINE
{ Send email, no attachments
====================================}
GLOBAL ROUTINE PS_SENDMAIL(
VALUE from_mail,
VALUE to_mail,
VALUE subject_line,
VALUE mail_body,
VALUE smtp_server,
VALUE smtp_port,
VALUE smtp_user,
VALUE smtp_password
)
DECLARE SEND_MAIL
IF (CHECK_POWERSHELL("") <> FALSE) THEN
SEND_MAIL = "$msg=New-Object System.Net.Mail.Mailmessage;" :
"$msg.from='" : from_mail : "';" :
"$msg.To.add('" : to_mail : "');" :
"$msg.subject='": subject_line : "';" :
"$msg.body='" : mail_body : "';" :
"$smtp=New-Object net.mail.smtpclient('" : smtp_server : "'," : smtp_port : ");" :
"$smtp.credentials=New-Object system.net.networkcredential('" : smtp_user : "','" : smtp_password : "');" :
"$smtp.send($msg);exit"
SPAWN "start " : ASCII(34) : "SM_PS_MAIL" : ASCII(34) : POWERSHELL : ASCII(34) : SEND_MAIL : ASCII(34) NOWAIT
ENDIF
ENDROUTINE
{ Send email, with attachment
====================================}
GLOBAL ROUTINE PS_SENDMAIL_ATTACH(
VALUE from_mail,
VALUE to_mail,
VALUE subject_line,
VALUE mail_body,
VALUE smtp_server,
VALUE smtp_port,
VALUE smtp_user,
VALUE smtp_password,
VALUE attachments
)
DECLARE SEND_MAIL_ATT
IF (CHECK_POWERSHELL("") <> FALSE) THEN
SEND_MAIL_ATT = "$msg=New-Object System.Net.Mail.Mailmessage;" :
"$msg.from='" : from_mail : "';" :
"$msg.To.add('" : to_mail : "');" :
"$msg.subject='": subject_line : "';" :
"$msg.body='" : mail_body : "';" :
"$msg.Attachments.Add('" : attachments : "');" :
"$smtp=New-Object net.mail.smtpclient('" : smtp_server : "'," : smtp_port : ");" :
"$smtp.credentials=New-Object system.net.networkcredential('" : smtp_user : "','" : smtp_password : "');" :
"$smtp.send($msg)"
SPAWN "start " : ASCII(34) : "SM_PS_MAIL" : ASCII(34) : POWERSHELL : ASCII(34) : SEND_MAIL_ATT : ASCII(34) NOWAIT
ENDIF
ENDROUTINE
{ Send email, body as HTML
====================================}
GLOBAL ROUTINE PS_SENDMAIL_HTML(
VALUE from_mail,
VALUE to_mail,
VALUE subject_line,
VALUE mail_body,
VALUE smtp_server,
VALUE smtp_port,
VALUE smtp_user,
VALUE smtp_password
)
DECLARE SEND_MAIL
IF (CHECK_POWERSHELL("") <> FALSE) THEN
SEND_MAIL = "$msg=New-Object System.Net.Mail.Mailmessage;" :
"$msg.from='" : from_mail : "';" :
"$msg.To.add('" : to_mail : "');" :
"$msg.subject='": subject_line : "';" :
"$msg.body='" : mail_body : "';" :
"$msg.IsBodyHTML=$true;" :
"$smtp=New-Object net.mail.smtpclient('" : smtp_server : "'," : smtp_port : ");" :
"$smtp.credentials=New-Object system.net.networkcredential('" : smtp_user : "','" : smtp_password : "');" :
"$smtp.send($msg);exit"
SPAWN "start " : ASCII(34) : "SM_PS_MAIL" : ASCII(34) : POWERSHELL : ASCII(34) : SEND_MAIL : ASCII(34) NOWAIT
ENDIF
ENDROUTINE