Skip to content

Commit 169fc7c

Browse files
authored
Merge pull request #11609 from umbraco/v9/bugfix/AB14726-fix-user-invite
Fix sending invite emails
2 parents fc49c8a + b8cd731 commit 169fc7c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Umbraco.Web.BackOffice/Controllers/UsersController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ private async Task SendUserInviteEmailAsync(UserBasic userDisplay, string from,
525525
var user = await _userManager.FindByIdAsync(((int) userDisplay.Id).ToString());
526526
var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
527527

528+
// Use info from SMTP Settings if configured, otherwise set fromEmail as fallback
529+
var senderEmail = !string.IsNullOrEmpty(_globalSettings.Smtp?.From) ? _globalSettings.Smtp.From : fromEmail;
530+
528531
var inviteToken = string.Format("{0}{1}{2}",
529532
(int)userDisplay.Id,
530533
WebUtility.UrlEncode("|"),
@@ -550,14 +553,14 @@ private async Task SendUserInviteEmailAsync(UserBasic userDisplay, string from,
550553
var emailBody = _localizedTextService.Localize("user","inviteEmailCopyFormat",
551554
//Ensure the culture of the found user is used for the email!
552555
UmbracoUserExtensions.GetUserCulture(to.Language, _localizedTextService, _globalSettings),
553-
new[] { userDisplay.Name, from, message, inviteUri.ToString(), fromEmail });
556+
new[] { userDisplay.Name, from, message, inviteUri.ToString(), senderEmail });
554557

555558
// This needs to be in the correct mailto format including the name, else
556559
// the name cannot be captured in the email sending notification.
557560
// i.e. "Some Person" <[email protected]>
558561
var toMailBoxAddress = new MailboxAddress(to.Name, to.Email);
559562

560-
var mailMessage = new EmailMessage(null /*use info from smtp settings*/, toMailBoxAddress.ToString(), emailSubject, emailBody, true);
563+
var mailMessage = new EmailMessage(senderEmail, toMailBoxAddress.ToString(), emailSubject, emailBody, true);
561564

562565
await _emailSender.SendAsync(mailMessage, Constants.Web.EmailTypes.UserInvite, true);
563566
}

0 commit comments

Comments
 (0)