Skip to content

Commit 88ecf79

Browse files
authored
Added inital files
Uploaded the generalized versions of the files following approval from my boss.
1 parent 636a170 commit 88ecf79

2 files changed

Lines changed: 328 additions & 0 deletions

File tree

Service_SMTP2Go/Service.ps1

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
################################################
2+
#Welcome to the Service Autostart Script with SMTP2Go API integration
3+
################################################
4+
5+
################################################
6+
#Service you wish to start, and the value of that service (Running or otherwise)
7+
################################################
8+
$Service_Name_Value = "<ServiceName>"
9+
$Service_Status_Value #Empty to start
10+
11+
################################################
12+
#Poll Service Status and information
13+
#
14+
$service = Get-Service -Name $Service_Name_Value -ErrorAction SilentlyContinue
15+
16+
################################################
17+
#Who you would like to send to, and from.
18+
################################################
19+
$From = "<Email Here>"
20+
$Recipients = "<Email Here>"
21+
$ReplyTo = "<Email Here>"
22+
23+
################################################
24+
#API Key & Template and other Data
25+
#
26+
$api_key = "<Your API Key Here>"
27+
$template_id = "<Template ID>"
28+
$hostname = Hostname
29+
30+
31+
################################################
32+
#The API Command to Post to SMTP2Go
33+
34+
function Send-APIEmail() {
35+
param
36+
(
37+
$counter,
38+
$error_output_value,
39+
$jsonBase,
40+
$api_key,
41+
$Recipients,
42+
$From,
43+
$template_id,
44+
$Service_Name_Value,
45+
$Service_Status_Value,
46+
$Pre_Service_Status_Value,
47+
$hostname
48+
)
49+
50+
################################################
51+
#Header Details, do not edit.
52+
#
53+
$headers = @{
54+
'Accept' = 'application/json'
55+
'Content-Type' = 'application/json'
56+
}
57+
58+
################################################
59+
#Format the payload.
60+
#
61+
$jsonBase = [ordered]@{
62+
'api_key' = "$api_key"
63+
'to' = @(
64+
"$Recipients"
65+
)
66+
'sender' = "$From"
67+
'template_id' = "$template_id"
68+
'template_data' = @{
69+
'Service_Name' = "$Service_Name_Value"
70+
'Service_Status' = "$Service_Status_Value"
71+
'Error_Output' = "$error_output_value"
72+
'Pre_Service_Status'= "$Pre_Service_Status_Value"
73+
'Hostname'= "$hostname"
74+
}
75+
#'custom_headers' = @{
76+
# 'header' = "Reply-To"
77+
# 'Reply-To' = "$ReplyTo"
78+
#}
79+
}
80+
################################################
81+
# Uncomment for testing variables Change the variable to see what it's printing out.
82+
#Write-Host $error_output_value
83+
################################################
84+
#Post the API-Request
85+
#
86+
Invoke-RestMethod "https://api.smtp2go.com/v3/email/send" -Method Post -Headers $headers -Body ($jsonBase|ConvertTo-Json) -ContentType "application/json"
87+
}
88+
89+
################################################
90+
#Tests if the service is running in Windows
91+
#
92+
93+
function Start-Service_Status($service) {
94+
95+
if ($service.Status -eq "Running") {
96+
$global:Pre_Service_Status_Value = "Running"
97+
$global:Service_Status_Value = "Running"
98+
$global:error_output_value = "No Errors Reported"
99+
} elseif ($service.Status -eq "Paused") {
100+
$global:Pre_Service_Status_Value = "Paused"
101+
$global:Service_Status_Value = "Paused"
102+
$global:error_output_value = $( $output = & Start-Service $service ) 2>&1
103+
} elseif ($service.Status -eq "Starting") {
104+
$global:Pre_Service_Status_Value = "Starting"
105+
$global:Service_Status_Value = "Starting"
106+
} elseif ($service.Status -eq "Stopped") {
107+
$global:Pre_Service_Status_Value = "Stopped"
108+
$global:Service_Status_Value = "Stopped"
109+
$global:error_output_value = $( $output = & Start-Service $service ) 2>&1
110+
} else {
111+
$global:Pre_Service_Status_Value = "Other"
112+
$global:Service_Status_Value = "Failure"
113+
$global:error_output_value = $( $output = & Start-Service $service ) 2>&1
114+
}
115+
}
116+
117+
################################################
118+
#Starts the Service Status Function
119+
#
120+
Start-Service_Status -service $service
121+
122+
123+
################################################
124+
#Ends if the service is running, or sends the email
125+
#then restarts the service status Function
126+
#
127+
128+
if ($Service_Status_Value -eq "Running") {
129+
exit 0
130+
} else {
131+
Send-APIEmail -counter $counter -api_key $api_key -Recipients $Recipients -From $From -template_id $template_id -Service_Name_Value $Service_Name_Value -Service_Status_Value $Service_Status_Value -error_output_value $error_output_value -Pre_Service_Status_Value $Pre_Service_Status_Value -hostname $hostname
132+
Start-Service_Status -Service $service
133+
}

Service_SMTP2Go/index.html

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6+
<title>{{ Hostname }} Notification about:{{ Service_Name }}</title>
7+
<style>
8+
@media only screen and (max-width: 620px) {
9+
table.body h1 {
10+
font-size: 28px !important;
11+
margin-bottom: 10px !important;
12+
}
13+
14+
table.body p,
15+
table.body ul,
16+
table.body ol,
17+
table.body td,
18+
table.body span,
19+
table.body a {
20+
font-size: 16px !important;
21+
}
22+
23+
table.body .wrapper,
24+
table.body .article {
25+
padding: 10px !important;
26+
}
27+
28+
table.body .content {
29+
padding: 0 !important;
30+
}
31+
32+
table.body .container {
33+
padding: 0 !important;
34+
width: 100% !important;
35+
}
36+
37+
table.body .main {
38+
border-left-width: 0 !important;
39+
border-radius: 0 !important;
40+
border-right-width: 0 !important;
41+
}
42+
43+
table.body .btn table {
44+
width: 100% !important;
45+
}
46+
47+
table.body .btn a {
48+
width: 100% !important;
49+
}
50+
51+
table.body .img-responsive {
52+
height: auto !important;
53+
max-width: 100% !important;
54+
width: auto !important;
55+
}
56+
}
57+
@media all {
58+
.ExternalClass {
59+
width: 100%;
60+
}
61+
62+
.ExternalClass,
63+
.ExternalClass p,
64+
.ExternalClass span,
65+
.ExternalClass font,
66+
.ExternalClass td,
67+
.ExternalClass div {
68+
line-height: 100%;
69+
}
70+
71+
.apple-link a {
72+
color: inherit !important;
73+
font-family: inherit !important;
74+
font-size: inherit !important;
75+
font-weight: inherit !important;
76+
line-height: inherit !important;
77+
text-decoration: none !important;
78+
}
79+
80+
#MessageViewBody a {
81+
color: inherit;
82+
text-decoration: none;
83+
font-size: inherit;
84+
font-family: inherit;
85+
font-weight: inherit;
86+
line-height: inherit;
87+
}
88+
89+
.btn-primary table td:hover {
90+
background-color: #34495e !important;
91+
}
92+
93+
.btn-primary a:hover {
94+
background-color: #34495e !important;
95+
border-color: #34495e !important;
96+
}
97+
}
98+
</style>
99+
</head>
100+
<body style="background-color: #f6f6f6; font-family: sans-serif; -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.4; margin: 0; padding: 0; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">
101+
<span class="preheader" style="color: transparent; display: none; height: 0; max-height: 0; max-width: 0; opacity: 0; overflow: hidden; mso-hide: all; visibility: hidden; width: 0;">{{ Service_Name }} was {{ Service_Status }}</span>
102+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="body" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background-color: #f6f6f6; width: 100%;" width="100%" bgcolor="#f6f6f6">
103+
<tr>
104+
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top;" valign="top">&nbsp;</td>
105+
<td class="container" style="font-family: sans-serif; font-size: 14px; vertical-align: top; display: block; max-width: 580px; padding: 10px; width: 580px; margin: 0 auto;" width="580" valign="top">
106+
<div class="content" style="box-sizing: border-box; display: block; margin: 0 auto; max-width: 580px; padding: 10px;">
107+
108+
<!-- START CENTERED WHITE CONTAINER -->
109+
<table role="presentation" class="main" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; background: #ffffff; border-radius: 3px; width: 100%;" width="100%">
110+
111+
<!-- START MAIN CONTENT AREA -->
112+
<tr>
113+
<td class="wrapper" style="font-family: sans-serif; font-size: 14px; vertical-align: top; box-sizing: border-box; padding: 20px;" valign="top">
114+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;" width="100%">
115+
<tr>
116+
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top;" valign="top">
117+
<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">Hello IT Department,</p>
118+
<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;" >Service: {{ Service_Name }} on {{ Hostname }}</p>
119+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="btn btn-primary" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; box-sizing: border-box; width: 100%;" width="100%">
120+
<tbody>
121+
<tr>
122+
<td align="left" style="font-family: sans-serif; font-size: 14px; vertical-align: top; padding-bottom: 15px;" valign="top">
123+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: auto;" align="center">
124+
<tbody>
125+
<tr>
126+
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top; border-radius: 5px; text-align: center; background-color: #3498db; padding: 4px;" valign="top" align="center" bgcolor="#3498db">Prior to the run, {{ Service_Name }} was {{ Pre_Service_Status }} </td>
127+
</tr>
128+
</tbody>
129+
</table>
130+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: auto;" align="center">
131+
<tbody>
132+
<tr>
133+
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top; border-radius: 5px; text-align: center; background-color: #3498db; padding: 4px;" valign="top" align="center" bgcolor="#3498db">On the last run, {{ Service_Name }} was {{ Service_Status }} </td>
134+
</tr>
135+
</tbody>
136+
</table>
137+
</td>
138+
</tr>
139+
</tbody>
140+
</table>
141+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" class="btn btn-primary" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; box-sizing: border-box; width: 100%;" width="100%">
142+
<tbody>
143+
<tr>
144+
<td align="left" style="font-family: sans-serif; font-size: 14px; vertical-align: top; padding-bottom: 15px;" valign="top">
145+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: auto;" align="center">
146+
<tbody>
147+
<tr>
148+
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top; border-radius: 5px; text-align: center; background-color: #3498db; padding: 4px;" valign="top" align="center" bgcolor="#3498db">During the attempt the following information was logged:<br>{{ Error_Output }}</td>
149+
</tr>
150+
</tbody>
151+
</table>
152+
</td>
153+
</tr>
154+
</tbody>
155+
</table>
156+
<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">Good luck!<br>From your favourite reporting service.</p>
157+
</td>
158+
</tr>
159+
</table>
160+
</td>
161+
</tr>
162+
163+
<!-- END MAIN CONTENT AREA -->
164+
</table>
165+
<!-- END CENTERED WHITE CONTAINER -->
166+
167+
<!-- START FOOTER -->
168+
<div class="footer" style="clear: both; margin-top: 10px; text-align: center; width: 100%;">
169+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;" width="100%">
170+
<tr>
171+
<td class="content-block" style="font-family: sans-serif; vertical-align: top; padding-bottom: 10px; padding-top: 10px; color: #999999; font-size: 12px; text-align: center;" valign="top">
172+
<span class="apple-link" style="color: #999999; font-size: 12px; text-align: center;">Helpful Links</span><br><a href="<!-- Your Link here -->" style="text-decoration: underline; color: #999999; font-size: 12px; text-align: center;" target="_blank" rel="noopener noreferrer">IT Sharepoint Homepage</a><br><a href="<!-- Your Link here -->" style="text-decoration: underline; color: #999999; font-size: 12px; text-align: center;" target="_blank" rel="noopener noreferrer">Sharepoint Wiki Pages</a>
173+
</td>
174+
</tr>
175+
</table>
176+
</div>
177+
<div class="footer" style="clear: both; margin-top: 10px; text-align: center; width: 100%;">
178+
<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;" width="100%">
179+
<tr>
180+
<td class="content-block" style="font-family: sans-serif; vertical-align: top; padding-bottom: 10px; padding-top: 10px; color: #999999; font-size: 12px; text-align: center;" valign="top">
181+
<span class="apple-link" style="color: #999999; font-size: 12px; text-align: center;">Generic Company, Address, City, State/Prov/Zip/PostCode</span>
182+
<br> Don't like these emails? <a href="<!-- Your Link here if you want -->" style="text-decoration: underline; color: #999999; font-size: 12px; text-align: center;" target="_blank" rel="noopener noreferrer">Too Bad You're IT.</a>
183+
</td>
184+
</tr>
185+
</table>
186+
</div>
187+
<!-- END FOOTER -->
188+
189+
</div>
190+
</td>
191+
<td style="font-family: sans-serif; font-size: 14px; vertical-align: top;" valign="top">&nbsp;</td>
192+
</tr>
193+
</table>
194+
</body>
195+
</html>

0 commit comments

Comments
 (0)