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

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.
parent e3d09057
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,15 @@ namespace AutoTx ...@@ -21,6 +21,15 @@ namespace AutoTx
writeLogDebug("SendEmail: " + subject + "\n" + body); writeLogDebug("SendEmail: " + subject + "\n" + body);
return; 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 { try {
var smtpClient = new SmtpClient() { var smtpClient = new SmtpClient() {
Port = _config.SmtpPort, Port = _config.SmtpPort,
...@@ -145,9 +154,7 @@ namespace AutoTx ...@@ -145,9 +154,7 @@ namespace AutoTx
try { try {
var body = LoadMailTemplate("Transfer-Success.txt", substitutions); var body = LoadMailTemplate("Transfer-Success.txt", substitutions);
SendEmail(GetEmailAddress(userDir), SendEmail(userDir, ServiceName + " - Transfer Notification", body);
ServiceName + " - Transfer Notification",
body);
} }
catch (Exception ex) { catch (Exception ex) {
writeLog("Error loading email template: " + ex.Message, true); writeLog("Error loading email template: " + ex.Message, true);
...@@ -173,7 +180,7 @@ namespace AutoTx ...@@ -173,7 +180,7 @@ namespace AutoTx
try { try {
var body = LoadMailTemplate("Transfer-Interrupted.txt", substitutions); var body = LoadMailTemplate("Transfer-Interrupted.txt", substitutions);
SendEmail(GetEmailAddress(userDir), SendEmail(userDir,
ServiceName + " - Transfer Interrupted - " + _config.HostAlias, ServiceName + " - Transfer Interrupted - " + _config.HostAlias,
body); body);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment