public async Task <bool> SendTestEmail(SettingsViewModel settings, string userId) { var response = true; try { var user = _dataProvider.GetUserById(userId); using (var client = new SmtpClient { Credentials = new NetworkCredential(settings.SmtpUsername, settings.SmtpPassword), EnableSsl = settings.SmtpUseSsl, Host = settings.SmtpHost, Port = int.Parse(settings.SmtpPort), Timeout = 10000 }) { var sendMailTask = client.SendMailAsync(user.Email, user.Email, "Test message from Panda!", "Congrats! Your email settings are working!"); if (await Task.WhenAny(sendMailTask, Task.Delay(5000)) == sendMailTask) { response = true; } else { // sendMailTask task timed out client.SendAsyncCancel(); response = false; } } } catch { response = false; } return(response); }
public ProfileSettingsViewModel GetProfileSettings(string userId) { var user = _dataProvider.GetUserById(userId); return(_mapper.Map <ProfileSettingsViewModel>(user)); }