/// <summary> /// /// </summary> /// <param name="user"></param> /// <remarks>TODO Move this to the helpers</remarks> private void SendConfirmationEmail(User user) { ReturnableUser retUser = new ReturnableUser(user, _keyAndIV); // decrypt user data // generate token string token = HelperMethods.GenerateJWTEmailConfirmationToken(retUser.ID, _configuration.GetValue <string>("EmailConfirmationTokenKey")); // handle to our smtp client var smtpClient = new SmtpClient(_configuration.GetValue <string>("Smtp:Host")) { Port = int.Parse(_configuration.GetValue <string>("Smtp:Port")), Credentials = new NetworkCredential(_configuration.GetValue <string>("Smtp:Username"), _configuration.GetValue <string>("Smtp:Password")), EnableSsl = true, }; // format the body of the message string body = "Hello " + retUser.First_Name + ",\n\n"; body += "A new account has been registered with SafeAccounts using your email address.\n\n"; body += "To confirm your new account, please go to this web address:\n\n"; body += _configuration.GetValue <string>("WebsiteUrl") + "emailconfirmation/?token=" + token + "&email=" + retUser.Email; body += "\n\nThis should appear as a blue link which you can just click on. If that doesn't work,"; body += "then cut and paste the address into the address line at the top of your web browser window.\n\n"; body += "If you need help, please contact the site administrator.\n\n"; body += "SafeAccounts Administrator,\n"; body += _configuration.GetValue <string>("Smtp:Username"); // handle to our message settings var mailMessage = new MailMessage { From = new MailAddress(_configuration.GetValue <string>("Smtp:Username")), Subject = "Confirm Your SafeAccounts Registration", Body = body, IsBodyHtml = false, }; mailMessage.To.Add(retUser.Email); // send message smtpClient.Send(mailMessage); }