Kaseya Community

Agent Procedure - Send email w/Attachment

This question has suggested answer(s)

I am trying to send an attachment from our Kaseya server. The attachments come from the machines and the procedure is running a transfer file. I think I am supposed to use the Get file, but I don't know where the files are stored on the Kaseya server.

I have installed Blat (command line email tool) to send email from our Kaseya server. I have a lot of machines that I want to perform a transfer file to a temp folder on the Kaseya server, and then send an email from the Kaseya server and attach the file and email to me. My question is, I don't know what kind of procedure to write to send the file. 

The procedure starts with:

  • Transfer File - The procedure is running on a machine to transfer the file to the Kaseya server (transfer file). It transfers the file from the source and the destination is KaseyaServer\temp\#vMachine.machName#\file.ext
  • What should my next procedure be? Is it a scheduled procedure that runs on the Kaseya server? How do I call on that file?

All Replies
  • I just did this the other day.. after I figured out that you can't do what you wanting to do with Kaseya natively.

    I ended up creating a powershell script that will send the file to the recipients that needed to get it.. Basically, Kaseya is executing the Powershell on certain times of the day.

  • This is quite tricky. I suggest you try:

    Step 1: use getFile() to have the file written from the endpoint to the Kaseya server. It will be placed in the endpoints 'private' folder on the Kaseya server. In our case we installed Kaseya server to D:\Kaseya so for us it would be D:\Kaseya\UserProfiles\<agent guid>\GetFiles\file.ext

    Step 2: in that same procedure use GetVariableUniversalCreate() to build a universal variable (help.kaseya.com/.../9030000). Define the universal variable as D:\Kaseya\UserProfiles\#vAgentConfiguration.agentGuid#\GetFiles\file.ext

    Step 3: in that same procedure use scheduleProcedure() to schedule a 'mailer' procedure to run *on your Kaseya server*.

    Step 4: The 'mailer' procedure should use GetVariableUniversalRead() to read in the universal variable (i.e. file path) you defined earlier. Your file path should then be available in the variable #global:universal1# - now you can use blat to attach that local file to an email. You can then optionally remove the file if you don't want it permanently kept on your Kaseya server).

    Let us know if you need more help, or if any of the above doesn't make sense :)

  • I use BLAT from blat.net to attach files to an email.

  • From what I remember, this works only if you know the agent ID of the system you're reading the variable, from, doesn't it? In other words, the GetVariableUniversalRead() step requires the variable name AND if you're reading from another machine (which you are) the agent ID of the machine you're reading from.

    In our case we wanted these mail steps to come from random machines on various customers and could never be sure of which agent was sending the variable, so this flow didn't work for us.

    If I'm wrong about that, please let me know, because this is a much simpler workflow than what I had to come up with.

    Nate

  • Ah yes - now you point out this limitation I recall how I worked around it previously.

    Assume we want to email an attachment from agent A through server S (or in fact transfer any job between two agents).

    1. Run a script against A that constructs a batch file containing the instructions to run on S. I used executeshellcommand to 'echo' content to the batch file one line at a time (don't forget to double up the angle brackets >>>>). In this case the batch file should contain the necessary 'blat' command and local filename to be emailed. The script should now transferFile() the batch to the server S into a predefined location (e.g. C:\transferred_batches\#vAgentConfiguration.AgentGuid#_blat.bat)

    2. The last line of this script schedules a second script on S that looks for batch files in C:\transferred_batches, validates they contain expected content, won't do anything harmful, and then runs them.

    If you wanted something 'safer' you could transferFile() the attachment into a specific filename format at the server side (e.g. c:\attachments\#vAgentConfiguration.AgentGuid#-recipient@domain-filename.ext) so that you could 'decode' the filename format and pass the relevant fields to 'blat'.

    I'll come up with some example code in the next day or two.