public async Task <string> SendTestEmailAsync(int userId, EmailOutgoingSettings outgoingSettings) { await _privilegesManager.Demand(userId, InstanceAdminPrivileges.ManageInstanceSettings); VerifyOutgoingSettings(outgoingSettings); var currentUser = await _userRepository.GetUserAsync(userId); if (string.IsNullOrWhiteSpace(currentUser.Email)) { throw new ConflictException("Your user profile does not include an email address. Please add one to receive a test email.", ErrorCodes.UserHasNoEmail); } var config = await GetEmailConfigAsync(outgoingSettings, currentUser); _emailHelper.Initialize(config); string body = EmailTemplateHelper.GetSendTestEmailTemplate(_websiteAddressService.GetWebsiteAddress()); try { _emailHelper.SendEmail(currentUser.Email, TestEmailSubject, body); return(currentUser.Email); } catch (EmailException ex) { throw new BadRequestException(ex.Message, ex.ErrorCode); } }