Email Example

From ProVide DocWiki
Revision as of 12:44, 19 June 2018 by Lukas Wiberg (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The following is the script that will send the email notifying the administrator that a new file has been uploaded.

# 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 page and select "OnUploadEnd" from the dropdown 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'.