Guest User

Untitled

a guest
Apr 24th, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. namespace Ebase.EmissorNFeWeb.Servicos
  2. {
  3. public class ServicoEmail
  4. {
  5.  
  6. public static async Task Execute(string Email, string Texto, string Mensagem)
  7. {
  8. try
  9. {
  10. MailMessage mailMsg = new MailMessage();
  11.  
  12. // To
  13. mailMsg.To.Add(new MailAddress(Email, "Ebase"));
  14.  
  15. // From
  16. mailMsg.From = new MailAddress("desenvolvimento@ebasesistemas.com.br", "Ebase");
  17.  
  18. // Subject and multipart/alternative Body
  19. mailMsg.Subject = "subject";
  20. string text = "text body";
  21. string html = @"<p>html body</p>";
  22. mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(text, null, MediaTypeNames.Text.Plain));
  23. mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));
  24.  
  25. // Init SmtpClient and send
  26. SmtpClient smtpClient = new SmtpClient("smtp.sendgrid.net", Convert.ToInt32(587));
  27. System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("desenvolvimento@ebasesistemas.com.br", "minhasenha");
  28. smtpClient.Credentials = credentials;
  29.  
  30. smtpClient.Send(mailMsg);
  31. }
  32. catch (Exception ex)
  33. {
  34. Console.WriteLine(ex.Message);
  35. }
  36. }
  37. }
  38. }
  39.  
  40. <system.net>
  41. <mailSettings>
  42. <smtp from="desenvolvimento@ebasesistemas.com.br">
  43. <network host="smtp.sendgrid.net" password="minhasenha" userName="Ebase" port="587" />
  44. </smtp>
  45. </mailSettings>
  46. </system.net>
  47.  
  48. [HttpPost]
  49. [AllowAnonymous]
  50. [ValidateAntiForgeryToken]
  51. public async Task<ActionResult> Register(RegisterViewModel model)
  52. {
  53. if (ModelState.IsValid)
  54. {
  55. var user = new ApplicationUser {
  56. NomeCompleto = model.NomeCompleto,
  57. UserName = model.NomeCompleto,
  58. Email = model.Email,
  59. EmpresaNome = model.EmpresaNome,
  60. Telefone = model.Telefone
  61. };
  62. var result = await UserManager.CreateAsync(user, model.Password);
  63. if (result.Succeeded)
  64. {
  65. await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
  66. // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
  67. // Send an email with this link
  68. // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
  69. // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
  70. // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href="" + callbackUrl + "">here</a>");
  71.  
  72. string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
  73. var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
  74. await ServicoEmail.Execute(model.Email, "Confirme a sua conta", "Confirme a sua conta clicando <a href="" + callbackUrl + "">AQUI</a>");
  75.  
  76.  
  77.  
  78. return RedirectToAction("Index", "Home");
  79. }
  80. AddErrors(result);
  81. }
  82. // If we got this far, something failed, redisplay form
  83. return View(model);
  84. }
  85.  
  86. @{
  87. ViewBag.Title = "Confirm Email";
  88. }
  89.  
  90. <h2>@ViewBag.Title.</h2>
  91. <div>
  92. <p>
  93. Obrigado por confirmar o seu email. Por favor @Html.ActionLink("Clique aqui para fazer o Login", "OnePage", "Home", routeValues: null, htmlAttributes: new { id = "loginLink" })
  94. </p>
  95. </div>
Add Comment
Please, Sign In to add comment