Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Ebase.EmissorNFeWeb.Servicos
- {
- public class ServicoEmail
- {
- public static async Task Execute(string Email, string Texto, string Mensagem)
- {
- try
- {
- MailMessage mailMsg = new MailMessage();
- // To
- mailMsg.To.Add(new MailAddress(Email, "Ebase"));
- // From
- mailMsg.From = new MailAddress("desenvolvimento@ebasesistemas.com.br", "Ebase");
- // Subject and multipart/alternative Body
- mailMsg.Subject = "subject";
- string text = "text body";
- string html = @"<p>html body</p>";
- mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(text, null, MediaTypeNames.Text.Plain));
- mailMsg.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html));
- // Init SmtpClient and send
- SmtpClient smtpClient = new SmtpClient("smtp.sendgrid.net", Convert.ToInt32(587));
- System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("desenvolvimento@ebasesistemas.com.br", "minhasenha");
- smtpClient.Credentials = credentials;
- smtpClient.Send(mailMsg);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- }
- <system.net>
- <mailSettings>
- <smtp from="desenvolvimento@ebasesistemas.com.br">
- <network host="smtp.sendgrid.net" password="minhasenha" userName="Ebase" port="587" />
- </smtp>
- </mailSettings>
- </system.net>
- [HttpPost]
- [AllowAnonymous]
- [ValidateAntiForgeryToken]
- public async Task<ActionResult> Register(RegisterViewModel model)
- {
- if (ModelState.IsValid)
- {
- var user = new ApplicationUser {
- NomeCompleto = model.NomeCompleto,
- UserName = model.NomeCompleto,
- Email = model.Email,
- EmpresaNome = model.EmpresaNome,
- Telefone = model.Telefone
- };
- var result = await UserManager.CreateAsync(user, model.Password);
- if (result.Succeeded)
- {
- await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
- // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
- // Send an email with this link
- // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
- // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
- // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href="" + callbackUrl + "">here</a>");
- string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
- var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
- await ServicoEmail.Execute(model.Email, "Confirme a sua conta", "Confirme a sua conta clicando <a href="" + callbackUrl + "">AQUI</a>");
- return RedirectToAction("Index", "Home");
- }
- AddErrors(result);
- }
- // If we got this far, something failed, redisplay form
- return View(model);
- }
- @{
- ViewBag.Title = "Confirm Email";
- }
- <h2>@ViewBag.Title.</h2>
- <div>
- <p>
- Obrigado por confirmar o seu email. Por favor @Html.ActionLink("Clique aqui para fazer o Login", "OnePage", "Home", routeValues: null, htmlAttributes: new { id = "loginLink" })
- </p>
- </div>
Add Comment
Please, Sign In to add comment