private void _sendMailAsync_DoWork(object sender, DoWorkEventArgs e) { string smtpHost = "smtp.gmail.com"; int smtpPort = 587; string login = "******"; string password = "******"; SmtpClient client = new SmtpClient(smtpHost, smtpPort) { Credentials = new NetworkCredential(login, password) }; string from = login; client.EnableSsl = true; ErrorOrSuccessTextBlock.Dispatcher.InvokeAsync(() => { string to = _server.GetTeacherByName(TeacherNameTextBox.Text).TeacherMail; string subj = "Восстановка мэйла"; string body = $"Ваш Guid = {_server.GetTeacherByName(TeacherNameTextBox.Text).TeacherGuid}"; MailMessage message = new MailMessage(from, to, subj, body); client.SendCompleted += Client_SendCompleted; try { client.SendMailAsync(message); } catch (Exception ex) { ErrorOrSuccessTextBlock.Text += ex; } }); Thread.Sleep(100); }