Difference between revisions of "Email Example"

From ProVide DocWiki
Jump to: navigation, search
(Created page with "The following is the script that will send the email notifying the administrator that a new file has been uploaded. <syntaxhighlight lang="powershell"> # Setup script paramete...")
 
Line 1: Line 1:
The following is the script that will send the email notifying the administrator that a new file has been uploaded.
+
For this example we'll use a powershell script that sends an email to the admin when a new file has been uploaded on the ProVide server.
 
<syntaxhighlight lang="powershell">
 
<syntaxhighlight lang="powershell">
 
# Setup script parameters
 
# Setup script parameters
Line 24: Line 24:
 
# The email text that will be sent will be what is contained within the '@"' in the start and the '"@' in the end.
 
# The email text that will be sent will be what is contained within the '@"' in the start and the '"@' in the end.
 
$Body = @"
 
$Body = @"
 
 
A new file has arrived through $ftp, ending up in $local.
 
A new file has arrived through $ftp, ending up in $local.
 
 
Best regards,
 
Best regards,
 
 
ProVide
 
ProVide
 
"@
 
"@
Line 49: Line 46:
  
  
We want this script to trigger when a user is done uploading a file so go to the "Messages and events" in the provide administrator page and select "OnUploadEnd" from the dropdown menu.
+
We want this script to trigger when a user is done uploading a file so go to the "Messages and events" in the provide administrator interface and select "OnUploadEnd" from the drop-down menu.
 
We want to add the follow line to the message box:  
 
We want to add the follow line to the message box:  
 
<syntaxhighlight lang="html5">%EXECUTE(Powershell.exe -File "c:\PATH\TO\SCRIPT\SCRIPT.ps1" -local "%LOCAL_FILENAME%" -ftp "%FTP_FILENAME%")%</syntaxhighlight>
 
<syntaxhighlight lang="html5">%EXECUTE(Powershell.exe -File "c:\PATH\TO\SCRIPT\SCRIPT.ps1" -local "%LOCAL_FILENAME%" -ftp "%FTP_FILENAME%")%</syntaxhighlight>
  
  
This line is telling provide that when the upload has been finished it will execute the powershell script located at the path and it will send with it the 'local_filename' and 'ftp_filename'.
+
This line is telling ProVide that when the upload has been finished it will execute the powershell script located at the path and it will send with it the 'local_filename' and 'ftp_filename'.

Revision as of 13:03, 20 June 2018

For this example we'll use a powershell script that sends an email to the admin when a new file has been uploaded on the ProVide server.

# Setup script parameters
param ([Parameter(Mandatory=$true)][string]$local, [Parameter(Mandatory=$true)][string]$ftp)


# Email parameters

$SMTPServer = "mailserver.domain.com"

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)

$SMTPClient.EnableSsl = $true

# The email address that will appear to be the sender of the email.
$EmailFrom = "from@domain.com"

# The email address that will receive the email.
$EmailTo = "to@domain.com"

# This will be the subject of the email.
$Subject = "New file"

# The email text that will be sent will be what is contained within the '@"' in the start and the '"@' in the end.
$Body = @"
A new file has arrived through $ftp, ending up in $local.
Best regards,
ProVide
"@




# If credentials are required for sending through this SMTP server

$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("domain\user", "password");


# If we should skip certification validation check for this SMTP server
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { return $true }

# Now we are ready to send the message

$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)


We want this script to trigger when a user is done uploading a file so go to the "Messages and events" in the provide administrator interface and select "OnUploadEnd" from the drop-down menu. We want to add the follow line to the message box:

%EXECUTE(Powershell.exe -File "c:\PATH\TO\SCRIPT\SCRIPT.ps1" -local "%LOCAL_FILENAME%" -ftp "%FTP_FILENAME%")%


This line is telling ProVide that when the upload has been finished it will execute the powershell script located at the path and it will send with it the 'local_filename' and 'ftp_filename'.