Kaseya Community

Script to attach file created to an email

  • Hi All,

    I have a script that outputs details to a CSV file, but when I upload this to the "dcoument" area on the Kaesya agent and open it, it is always seen as a web page and not exel. I thought then a way around this is that I would be able to attach this csv file to an email within the script when generated instead of uploading it to the "doument" area.

    can anyone help please ?


    Legacy Forum Name: Script to attach file created to an email,
    Legacy Posted By Username: dstrong
  • There are two workarounds for getting the file from "Get Files"

    1. Open it in the browser, select all, and paste into notepad or Excel. Works great, but it is extra steps.
    2. Access the file directly from the KServer! If this option is available to you, it should work fine, but just be warned that direct access to the KServer is not generally a good idea to open up to end-users.

    A workaround for the risks in #2 would be this:
    Setup offsite replication to replicate the "Get Files" area to another machine, and give access to the replicated copy of those files.

    The limitation is that the "Get Files" folder is one of several folders, per machine, so setting it up to access all "Get Files" across the board is going to give you a very unwieldy structure to traverse in order to actually get your files; in addition, they are organized by GUID and not by name, so finding the one you want is a 2-step process at best.
    The files are located in C:\Kaseya\UserProfiles\GUID\GetFiles on the KServer.

    Legacy Forum Name: How-To,
    Legacy Posted By Username: Matthew Bartels
  • I don't think there is an easy way to email a file from a script though... It's cumbersome enough to even put a line break into the body of the email generated in a "Send Email" Scripting step - attaching a file seems beyond the capabilities.

    I say there's no easy way... here's the "hard way"
    1. get uuencode.exe from here
    2. Upload it to your KServer
    3. Write a script like this one:

    Script Name: Attach file via Email Step Demo
    Script Description:

    IF True
    Write File
    Parameter 1 : #vAgentConfiguration.agentTempDir#\tools\uuencode.exe
    Parameter 2 : VSASharedFiles\CMDLineUtils\UUENCODE.EXE
    OS Type : 0
    Execute Shell Command
    Parameter 1 : dir c:\ >> #vAgentConfiguration.agentTempDir#\directorylisting.bin
    Parameter 2 : 0
    OS Type : 0
    Execute Shell Command
    Parameter 1 : #vAgentConfiguration.agentTempDir#\tools\uuencode.exe #vAgentConfiguration.agentTempDir#\directorylisting.bin #vAgentConfiguration.agentTempDir#\directorylisting.txt
    Parameter 2 : 0
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : #vAgentConfiguration.agentTempDir#\directorylisting.txt
    Parameter 3 : attachme
    OS Type : 0
    Send Email
    Parameter 1 : user@company.com
    Parameter 2 : UUEncoded file attached
    Parameter 3 : #attachme#
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : #attachme#
    OS Type : 0

    Of course, you'll have to use UUDECODE.EXE when you receive the email; and I don't know the size limitation of what a Variable will hold; if the converted file is longer than that it won't make it through.

    But it is "a" way, there might be better ways, but I've tested this and it works.

    Legacy Forum Name: How-To,
    Legacy Posted By Username: Matthew Bartels