From 74cf1f03d668a321987ab9110d0be6cbabb16254 Mon Sep 17 00:00:00 2001 From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch> Date: Mon, 18 Dec 2017 16:46:18 +0100 Subject: [PATCH] Auto-resolve AD user names as email recipient. Plus make sure to not attempting to send the mail message if the account name can't be resolved to an email address. --- AutoTx/Email.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/AutoTx/Email.cs b/AutoTx/Email.cs index 013008c..cb90c15 100644 --- a/AutoTx/Email.cs +++ b/AutoTx/Email.cs @@ -21,6 +21,15 @@ namespace AutoTx writeLogDebug("SendEmail: " + subject + "\n" + body); return; } + if (!recipient.Contains(@"@")) { + writeLogDebug("Invalid recipient, trying to resolve via AD: " + recipient); + recipient = GetEmailAddress(recipient); + } + if (string.IsNullOrWhiteSpace(recipient)) { + writeLogDebug("Invalid or empty recipient given, NOT sending email!"); + writeLogDebug("SendEmail: " + subject + "\n" + body); + return; + } try { var smtpClient = new SmtpClient() { Port = _config.SmtpPort, @@ -145,9 +154,7 @@ namespace AutoTx try { var body = LoadMailTemplate("Transfer-Success.txt", substitutions); - SendEmail(GetEmailAddress(userDir), - ServiceName + " - Transfer Notification", - body); + SendEmail(userDir, ServiceName + " - Transfer Notification", body); } catch (Exception ex) { writeLog("Error loading email template: " + ex.Message, true); @@ -173,7 +180,7 @@ namespace AutoTx try { var body = LoadMailTemplate("Transfer-Interrupted.txt", substitutions); - SendEmail(GetEmailAddress(userDir), + SendEmail(userDir, ServiceName + " - Transfer Interrupted - " + _config.HostAlias, body); } -- GitLab