-- load required modules local email = require("email") local log = require("log") local inspect = require("inspect") -- define a predetermined param object for test purposes if params == nil then params = { domain = "testdomain.com", hook = "BackupDomainComplete", task = { ErrorCount = 0, Status = "success", TotalFileCount = 3, TotalFileSize = 2131 } } end log.infof("lua hook params %s", inspect(params)) -- define the function to return data size in human-readable format local sizeUnits = {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"} function ReadableSize(s) local i = 1 while s > 1024 do s = s / 1024 i = i + 1 end return string.format("%.2f %s", s, sizeUnits[i]) end -- define the email subject, body and recipient local recipient = "recipient@mydomain.com" local subject = "Backup accomplished" local html = {} table.insert(html, "Backup for " .. params.domain .. " accomplished") table.insert(html, "status:" .. params.task.Status) table.insert(html, "file count:" .. params.task.TotalFileCount) table.insert(html, "file size:" .. ReadableSize(params.task.TotalFileSize)) table.insert(html, "errors:" .. params.task.ErrorCount) html = table.concat(html, "
") local err = email.send(recipient, subject, html) -- print the hook event and any errors in the CubeBackup log file if err then log.errorf("send mail failed:%s", err) else log.infof("mail sent.") end