Skip to content

Commit b6aac5e

Browse files
authored
Merge pull request #1 from timothiasthegreat/main
Fixed Reply To Functionality
2 parents c7c7f39 + 041bf32 commit b6aac5e

2 files changed

Lines changed: 50 additions & 27 deletions

File tree

Service_SMTP2Go/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ Should look similar to this:
1010
vars.txt - The variables used in the template and formatted for SMTP2Go
1111
service.ps1 - The Powershell document to notify about, and automatically restart the service with notification
1212

13+
# Setup
14+
- Create an SMTP2Go account and fulfil setup with verified Sender domain. [Get Started - SMTP2GO Documentation](https://support.smtp2go.com/hc/en-gb/articles/12747932085145-Getting-Started-with-SMTP2GO)
15+
- Add Template to SMTP2Go using HTML from `index.html` in this repo. Note the "Template ID" [API Templates](https://support.smtp2go.com/hc/en-gb/articles/4402929434777-API-Templates)
16+
- Set up an API Key [API Keys](https://support.smtp2go.com/hc/en-gb/articles/20733554340249-API-Keys)
17+
- Clone this Repo or download `Service.ps1` and edit the script whith the appropriate information
18+
- Monitored Service Name
19+
- From Name and Email
20+
- Recipient Email
21+
- Reply-To Name eand Email (If applicable)
22+
- API Key
23+
- Template ID
24+
Set script to run on a schedule using your preferred method
1325

1426
# Original E-mail Template is from:
1527
https://github.com/leemunroe/responsive-html-email-template

Service_SMTP2Go/Service.ps1

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
################################################
22
#Welcome to the Service Autostart Script with SMTP2Go API integration
33
################################################
4-
4+
#Configuration Section
55
################################################
66
#Service you wish to start, and the value of that service (Running or otherwise)
77
################################################
8-
$Service_Name_Value = "<ServiceName>"
9-
$Service_Status_Value #Empty to start
8+
$Service_Name_Value = "Name of Service"
109

1110
################################################
12-
#Poll Service Status and information
13-
#
14-
$service = Get-Service -Name $Service_Name_Value -ErrorAction SilentlyContinue
11+
#Who you would like to send to, and from.
12+
################################################
13+
$From_Name = "<From Name>"
14+
$From_email = "<From Email Address>"
15+
#Single Email Recipient
16+
$Recipient = "<To Email Address>"
1517

1618
################################################
17-
#Who you would like to send to, and from.
19+
#If you want to define a different Reply-To than
20+
#the From address uncomment the below variables and adjust
1821
################################################
19-
$From = "<Email Here>"
20-
$Recipients = "<Email Here>"
21-
# Reply-to is not currently enabled, and is not currently functioning.
22-
# Please do a pull request if you get it working. :P
23-
$ReplyTo = "<Email Here>"
22+
#$ReplyTo_Name = "<Reply To Name>"
23+
#$ReplyTo_email = "<Reply To Email>"
2424

2525
################################################
26-
#API Key & Template and other Data
27-
#
28-
$api_key = "<Your API Key Here>"
29-
$template_id = "<Template ID>"
30-
$hostname = Hostname
26+
#SMTP2GO API Key & Template and other Data
27+
################################################
28+
$api_key = "<API-KEY>"
29+
$template_id = "<TEMPLATE-ID>"
30+
$hostname = $env:COMPUTERNAME #Edit to override Computer's configured Hostname
3131

32+
################################################
33+
#DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
34+
################################################
35+
$Service_Status_Value #Empty to start
36+
$service = Get-Service -Name $Service_Name_Value -ErrorAction SilentlyContinue
3237

3338
################################################
3439
#The API Command to Post to SMTP2Go
@@ -40,8 +45,11 @@ function Send-APIEmail() {
4045
$error_output_value,
4146
$jsonBase,
4247
$api_key,
43-
$Recipients,
44-
$From,
48+
$Recipient,
49+
$From_Name,
50+
$From_email,
51+
$ReplyTo_Name,
52+
$ReplyTo_email,
4553
$template_id,
4654
$Service_Name_Value,
4755
$Service_Status_Value,
@@ -63,9 +71,9 @@ $headers = @{
6371
$jsonBase = [ordered]@{
6472
'api_key' = "$api_key"
6573
'to' = @(
66-
"$Recipients"
74+
"$Recipient"
6775
)
68-
'sender' = "$From"
76+
'sender' = "$From_Name <$From_email>"
6977
'template_id' = "$template_id"
7078
'template_data' = @{
7179
'Service_Name' = "$Service_Name_Value"
@@ -74,17 +82,20 @@ $headers = @{
7482
'Pre_Service_Status'= "$Pre_Service_Status_Value"
7583
'Hostname'= "$hostname"
7684
}
77-
#'custom_headers' = @{
78-
# 'header' = "Reply-To"
79-
# 'Reply-To' = "$ReplyTo"
80-
#}
85+
}
86+
if ($ReplyTo_email -ne $null) {
87+
$jsonBase['custom_headers'] = @(
88+
@{
89+
'header' = "Reply-To"
90+
'value' = "$ReplyTo_Name <$ReplyTo_email>"
91+
}
92+
)
8193
}
8294
################################################
8395
# Uncomment for testing variables Change the variable to see what it's printing out.
8496
#Write-Host $error_output_value
8597
################################################
8698
#Post the API-Request
87-
#
8899
Invoke-RestMethod "https://api.smtp2go.com/v3/email/send" -Method Post -Headers $headers -Body ($jsonBase|ConvertTo-Json) -ContentType "application/json"
89100
}
90101

@@ -130,6 +141,6 @@ Start-Service_Status -service $service
130141
if ($Service_Status_Value -eq "Running") {
131142
exit 0
132143
} else {
133-
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
144+
Send-APIEmail -counter $counter -api_key $api_key -Recipient $Recipient -From_Name $From_Name -From_email $From_email -ReplyTo_Name $ReplyTo_Name -ReplyTo_email $ReplyTo_email -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
134145
Start-Service_Status -Service $service
135146
}

0 commit comments

Comments
 (0)