Page 1 of 1
Attach file using Send e-mail processor
Posted: Wed Aug 19, 2020 4:59 am
by Ben
Hello,
Almost every day I'm thinking of some new way to use FFAStrans to automate my life and am so thankful for this software!
One thing I'd love to do is add a file to a folder on my computer and FFAstrans to then attach that file to an email and send it off.
Perhaps I've missed it but email attachments would be awesome!
Cheers,
Ben
Re: Attach file using Send e-mail processor
Posted: Wed Aug 19, 2020 8:57 am
by emcodem
Hi @Ben
welcome to the forum and thank you for using ffastrans!
You are right, currently the built in "Email" processor cannot attach files. You could probably embed an image into the email using html data uris but this is not what you want. Not sure if @admin will add this function in short time.
As a workaround, use this in a commandline executor (and exactly this, no cmd /C or such, just change the emails and smtpserver name) :
Code: Select all
PowerShell -Command "& {Send-MailMessage -From 'emcodem@ffastrans.com' -To 'admin@ffastrans.com' -Subject 'Test Subject' -Body 'Test Body' -SmtpServer 'smtp.domain.local' -Attachments 'c:\folder\file_to_send.txt'}"
Re: Attach file using Send e-mail processor
Posted: Wed Aug 19, 2020 8:42 pm
by admin
Hi Ben
Thanks for your request, it's noted. Should not be too hard but this feature will not be added for the upcoming version 1.1.0. So you probably need to wait for 1.1.x+.
-steinar
Re: Attach file using Send e-mail processor
Posted: Wed Aug 19, 2020 9:39 pm
by Ben
Hey @emcodem. Thanks for the code! However when I use it runs successfully but no emails come through. If I could get the code working would it be able to dynamically attach the file that has been put in the folder, or only a single file that's the same each time?
Hey Steinar, wow thanks for noting the request. I'd be so cool to have it added. My use case is that I edit a weekly TV show and once a month I need to email off the broadcast synopsis & titles in a spreadsheet. So I'd like to add the file in a folder and it automatically email them. But for now I can just make a workflow to add the file to a Dropbox folder and just share the same Dropbox folder link each time and let them know it's been added
Thanks!
Re: Attach file using Send e-mail processor
Posted: Thu Aug 20, 2020 7:58 am
by emcodem
Hey Ben,
it depends a little on your smtp settings, does your smtp server need authentification (username/password) or encryption?
Multiple attachments would look like this:
-Attachments “c:\temp\server1-uptime-report.txt”, “c:\temp\server2-uptime-report.txt”
Re: Attach file using Send e-mail processor
Posted: Thu Aug 20, 2020 8:02 am
by Ben
I was just testing it using smtp.gmail.com so yeah I'd need the username and password. I've turned on less secure apps for my gmail account so long as I put in the username and password it should work. How would I put in the authentication?
Great thanks for the multiple attachments code
Re: Attach file using Send e-mail processor
Posted: Thu Aug 20, 2020 8:58 am
by emcodem
Wooow, i just see that submitting a username and password seems to be nearly impossible with the powershell solution above. There is a way but really complicated. Let me check for an alternative, stay tuned!
Re: Attach file using Send e-mail processor
Posted: Thu Aug 20, 2020 9:20 am
by emcodem
OK i found out how it works in one line. So here the complete example for gmail and multiple attachments.
You need to change every occurence of
emcodem@gmail.com and SOMEPASSWORD and the paths to the files...
As you pointed out, in the gmail settings one needs to enable "less secure apps".
Code: Select all
PowerShell -Command "& {Send-MailMessage -Attachments 'c:\dev\file_to_send.txt','c:\dev\file_to_send 2.txt' -Subject 'Test Subject' -Body 'Test Body' -From 'emcodem@gmail.com' -To 'emcodem@gmail.com' -SmtpServer 'smtp.gmail.com' -port "587" -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'emcodem@gmail.com', (ConvertTo-SecureString -String "SOMEPASSWORD" -AsPlainText -Force)) -UseSsl} "
If you want some complex email body or email body should be html, you can use the write text file processor, write your text to a file and then replace the -Body 'test body' from above with this
Code: Select all
-Body (Get-Content -Path '%s_source%' | Out-String) -BodyAsHtml
And if you need the same email settings in multiple workflows, you can use STATIC variables to store the smtp related stuff, like
Static variable with SMTP stuff:
Code: Select all
%s_SMTP% = -From 'emcodem@gmail.com' -SmtpServer 'smtp.gmail.com' -port "587" -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'emcodem@gmail.com', (ConvertTo-SecureString -String "SOMEPASSWORD" -AsPlainText -Force)) -UseSsl
Code of commandline processor:
Code: Select all
PowerShell -Command "& {Send-MailMessage -Attachments 'c:\dev\file_to_send.txt','c:\dev\file_to_send 2.txt' -Subject 'Test Subject' -Body 'Test Body' -To 'emcodem@gmail.com' %s_SMTP%}"
By the way, @admin i never got gmail smtp working with ffastrans stock functionality, do you know if this works? If not i guess we have another feature request in this thread hehe