We are going to use powershell for that, so it will only work with operating systems that have powershell support.
Here is the simple way i found to achieve that:
1. Create a powershell script file, for example smtp.ps1 with the following content:
$lastfile = gci $env:USERPROFILE\Appdata\roaming\freefilesync\Logs | sort LastWriteTime | select -last 1
$emailattachment = $env:USERPROFILE + "\Appdata\roaming\freefilesync\Logs\" + $lastfile
$EmailFrom = “Source Email”
$EmailTo = “Destination Email”
$Subject = “Your Subjet Here”
$Body = “Your Message Here”
$mailmessage = New-Object system.net.mail.mailmessage
$mailmessage.from = ($EmailFrom)
$mailmessage.To.add($EmailTo)
$mailmessage.Subject = $Subject
$mailmessage.Body = $Body
$attachment = New-Object System.Net.Mail.Attachment($emailattachment, 'text/plain')
$mailmessage.Attachments.Add($attachment)
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“EMAIL USERNAME HERE”, “EMAIL PASSWORD HERE”);
$SMTPClient.Send($mailmessage)
2. Put the above file in a folder, for example d:\smtp
3. Put the following script execution command in the job´s options command execution, choosing the alert on option that better suites you: powershell.exe -executionpolicy unrestricted -command d:\smtp\smtp.ps1
That´s all you need to achieve receiving email notifications of FreeFileSync Jobs.
If you need to hide your email credentials on the script you can encrypt the smtp.ps1 file (or whatever name you gave to it) by doing the following:
1. Create another script with the following content, give it a name, for example encrypt.ps1:
function Encrypt-Script($path, $destination) {
$script = Get-Content $path | Out-String
$secure = ConvertTo-SecureString $script -asPlainText -force
$export = $secure | ConvertFrom-SecureString
Set-Content $destination $export
"Script '$path' has been encrypted as '$destination'"
}
Encrypt-Script $PWD\smtp.ps1 $PWD\smtp.bin
It will create a smtp.bin (encrypted script) file in the current folder.
3. Now you have to create a decrypt script with the following code to execute the encrypted bin file, give it a name , for example smtpexe.ps1:
function Execute-EncryptedScript($path) {
trap { "Decryption failed"; break }
$raw = Get-Content $path
$secure = ConvertTo-SecureString $raw
$helper = New-Object system.Management.Automation.PSCredential("test", $secure)
$plain = $helper.GetNetworkCredential().Password
Invoke-Expression $plain
}
Execute-EncryptedScript "PATH OF THE BIN FILE"\smtp.bin
4. The execution code you should put on FreeFileSync job´s options command execution is: powershell.exe -executionpolicy unrestricted -command d:\smtp\smtpexe.ps1
And thats it, simple, isn´t it!?
Hope it helps someone.
Best regards