diff --git a/AutoTx/AutoTx.cs b/AutoTx/AutoTx.cs index 2a792348bf95a84d2735a12edbcacda9bc0f995f..e8e4d4e34cfadfffeec091ea0bccbec482ff791c 100644 --- a/AutoTx/AutoTx.cs +++ b/AutoTx/AutoTx.cs @@ -342,7 +342,7 @@ namespace AutoTx writeLog("Not all files were transferred - will resume upon next start"); writeLogDebug("CurrentTransferSrc: " + _status.CurrentTransferSrc); // should we delete an incompletely transferred file on the target? - // TODO: send a notification to the user of the interrupted transfer (#38) + SendTransferInterruptedMail(); } // set the shutdown status to clean: _status.CleanShutdown = true; diff --git a/AutoTx/Email.cs b/AutoTx/Email.cs index 49b8b9b648b6027cf4ffbbee6b9cf3d475790acf..013008cfdfd5202d5bfb94cdf066914317154eef 100644 --- a/AutoTx/Email.cs +++ b/AutoTx/Email.cs @@ -153,5 +153,33 @@ namespace AutoTx writeLog("Error loading email template: " + ex.Message, true); } } + + /// <summary> + /// Send a notification email when a transfer has been interrupted before completion. + /// Recipient address is derived from the global variable CurrentTransferSrc. + /// </summary> + public void SendTransferInterruptedMail() { + if (_config.SendTransferNotification == false) + return; + + var userDir = new DirectoryInfo(_status.CurrentTransferSrc).Name; + + var substitutions = new List<Tuple<string, string>> { + Tuple.Create("FACILITY_USER", GetFullUserName(userDir)), + Tuple.Create("HOST_ALIAS", _config.HostAlias), + Tuple.Create("HOST_NAME", Environment.MachineName), + Tuple.Create("EMAIL_FROM", _config.EmailFrom) + }; + + try { + var body = LoadMailTemplate("Transfer-Interrupted.txt", substitutions); + SendEmail(GetEmailAddress(userDir), + ServiceName + " - Transfer Interrupted - " + _config.HostAlias, + body); + } + catch (Exception ex) { + writeLog("Error loading email template: " + ex.Message, true); + } + } } } \ No newline at end of file diff --git a/AutoTx/Resources/Mail-Templates/Transfer-Interrupted.txt b/AutoTx/Resources/Mail-Templates/Transfer-Interrupted.txt new file mode 100644 index 0000000000000000000000000000000000000000..740b517c8a5663aa83d1a865341dc8851eb39f06 --- /dev/null +++ b/AutoTx/Resources/Mail-Templates/Transfer-Interrupted.txt @@ -0,0 +1,15 @@ +Dear FACILITY_USER, + +unfortunately the transfer service on "HOST_ALIAS" (HOST_NAME) +has been stopped while one of your transfers was still running, probably +due the computer being shut down. + +Your transfer will resume without any additional action required once the +service is started again, which happens automatically when the computer has +finished booting up again. + + +Don't hesitate to contact EMAIL_FROM if you have any additional question. + +Have a nice day +The Facility Team