Skip to content
Snippets Groups Projects
Commit aae35948 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Always include host alias in mail subjects.

parent 431f4117
Branches
Tags
No related merge requests found
...@@ -17,7 +17,7 @@ namespace ATxService ...@@ -17,7 +17,7 @@ namespace ATxService
/// <param name="subject">The subject, might be prefixed with a configurable string.</param> /// <param name="subject">The subject, might be prefixed with a configurable string.</param>
/// <param name="body">The email body.</param> /// <param name="body">The email body.</param>
private void SendEmail(string recipient, string subject, string body) { private void SendEmail(string recipient, string subject, string body) {
subject = _config.EmailPrefix + subject; subject = $"{_config.EmailPrefix}{ServiceName} - {subject} - {_config.HostAlias}";
body += $"\n\n--\n[{_versionSummary}]\n"; body += $"\n\n--\n[{_versionSummary}]\n";
if (string.IsNullOrEmpty(_config.SmtpHost)) { if (string.IsNullOrEmpty(_config.SmtpHost)) {
Log.Debug("SendEmail: {0}\n{1}", subject, body); Log.Debug("SendEmail: {0}\n{1}", subject, body);
...@@ -89,9 +89,9 @@ namespace ATxService ...@@ -89,9 +89,9 @@ namespace ATxService
return; return;
} }
if (subject == "") { if (string.IsNullOrWhiteSpace(subject))
subject = $"{ServiceName} - {Environment.MachineName} - Admin Notification"; subject = "Admin Notification";
}
body = $"Notification from: {_config.HostAlias} ({Environment.MachineName})\n\n{body}"; body = $"Notification from: {_config.HostAlias} ({Environment.MachineName})\n\n{body}";
Log.Debug("Sending an admin notification email."); Log.Debug("Sending an admin notification email.");
SendEmail(_config.AdminEmailAdress, subject, body); SendEmail(_config.AdminEmailAdress, subject, body);
...@@ -127,8 +127,7 @@ namespace ATxService ...@@ -127,8 +127,7 @@ namespace ATxService
}; };
try { try {
var body = LoadMailTemplate("DiskSpace-Low.txt", substitutions); var body = LoadMailTemplate("DiskSpace-Low.txt", substitutions);
var subject = $"Low Disk Space On {_config.HostAlias}"; SendEmail(_config.AdminEmailAdress, "low disk space", body);
SendEmail(_config.AdminEmailAdress, subject, body);
} }
catch (Exception ex) { catch (Exception ex) {
Log.Error("Error loading email template: {0}", ex.Message); Log.Error("Error loading email template: {0}", ex.Message);
...@@ -162,7 +161,7 @@ namespace ATxService ...@@ -162,7 +161,7 @@ namespace ATxService
try { try {
var body = LoadMailTemplate("Transfer-Success.txt", substitutions); var body = LoadMailTemplate("Transfer-Success.txt", substitutions);
SendEmail(userDir, $"{ServiceName} - Transfer Notification", body); SendEmail(userDir, "Transfer Notification", body);
Log.Debug("Sent transfer completed notification to {0}", userDir); Log.Debug("Sent transfer completed notification to {0}", userDir);
} }
catch (Exception ex) { catch (Exception ex) {
...@@ -189,9 +188,7 @@ namespace ATxService ...@@ -189,9 +188,7 @@ namespace ATxService
try { try {
var body = LoadMailTemplate("Transfer-Interrupted.txt", substitutions); var body = LoadMailTemplate("Transfer-Interrupted.txt", substitutions);
SendEmail(userDir, SendEmail(userDir, "INTERRUPTED Transfer", body);
$"{ServiceName} - Transfer Interrupted - {_config.HostAlias}",
body);
} }
catch (Exception ex) { catch (Exception ex) {
Log.Error("Error loading email template: {0}", ex.Message); Log.Error("Error loading email template: {0}", ex.Message);
...@@ -218,7 +215,7 @@ namespace ATxService ...@@ -218,7 +215,7 @@ namespace ATxService
return report; return report;
_status.LastGraceNotification = DateTime.Now; _status.LastGraceNotification = DateTime.Now;
SendAdminEmail(report, $"{_config.HostAlias}: grace location cleanup required."); SendAdminEmail(report, "grace location summary");
return report + "\nNotification sent to AdminEmailAdress.\n"; return report + "\nNotification sent to AdminEmailAdress.\n";
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment