Get FFS to send an email

Discuss new features and functions
Posts: 8
Joined: 11 Sep 2016

djms1.618

There are loads of ways to install a commandline SMTP client, but Powershell has one built in and so you can configure FFS to run the powershell script at the end. Here are my notes to myself on how, pieced together from suggestions around the web...

Step One

Save the smtp email password in a secure format. Save it to the same location of the FFS log file we want to attach. Use this folder going forward. Folder is %UserProfile%\AppData\Roaming\FreeFileSync\
Do so with this command in powershell (do not run as administrator)

Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File -FilePath $env:userprofile\Appdata\Roaming\FreeFileSync\EmailAuthCert

you will be prompted for the smtp password

Step Two
Prepare the computer to accept a home-brew script.
In powershell (DO this time run powershell as administrator) run the following command

Set-ExecutionPolicy remotesigned

Step Three

Take this script and alter lines 1-7 as required. Remove the last switch on line 8 if SSL is not supported. Save script to %UserProfile%\AppData\Roaming\FreeFileSync\email.ps1

$From = "user1@domain.com"
$Subject = "FFS Back-up Log"
$To = "user2@domain.com"
$Emailusername = "user1@domain.com_or_something_different_if_thats_how_yours_works"
$SMTP_Port = "587"
$SMTP_Server = "smtp.domain.com"
$Body = "Whatever body you want and you can use html tags. Just whatever you do, put it on one line!"
Send-MailMessage -From $From -Subject $Subject -To $To -Attachments $env:userprofile\Appdata\roaming\freefilesync\LastSyncs.log -Body $Body -BodyAsHtml -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Emailusername,(Get-Content -Path $env:userprofile\Appdata\roaming\freefilesync\EmailAuthCert | ConvertTo-SecureString)) -Port $SMTP_Port -SmtpServer $SMTP_Server -UseSsl

Step Four

Configure FFS and in the Sync settings box, On Completion box enter: powershell %userprofile%\Appdata\Roaming\FreeFileSync\email.ps1

Whaddaya think??

Dave
Posts: 8
Joined: 11 Sep 2016

djms1.618

HEADS UP!! Original powershell in Windows 7 does not support alternate port numbers for SMTP. Edit the final line to not include ''-Port $SMTP_Port'' and remove line 5. OR if you require alternate portnumber function to send out, upgrade powershell in Windows to v3.0
https://msdn.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell#BKMK_InstallingOnWindows7andWindowsServer2008R2
User avatar
Site Admin
Posts: 7050
Joined: 9 Dec 2007

Zenju

Email notifications are now directly supported with FreeFileSync 10.20!