Getting info on email sent

This commit is contained in:
2018-07-12 18:11:29 +02:00
parent 89937cb532
commit c6b559b7ab
6 changed files with 28 additions and 13 deletions

View File

@ -1,5 +1,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Yavsc.Abstract.Manage;
namespace Yavsc.Services namespace Yavsc.Services
{ {
@ -13,6 +14,6 @@ namespace Yavsc.Services
/// <param name="subject">email subject</param> /// <param name="subject">email subject</param>
/// <param name="message">message</param> /// <param name="message">message</param>
/// <returns>the message id</returns> /// <returns>the message id</returns>
Task<string> SendEmailAsync(string username, string email, string subject, string message); Task<EmailSentViewModel> SendEmailAsync(string username, string email, string subject, string message);
} }
} }

View File

@ -0,0 +1,10 @@
namespace Yavsc.Abstract.Manage
{
public class EmailSentViewModel
{
public string EMail { get; set; }
public string MessageId { get; set; }
public bool Sent { get; set; }
public string ErrorMessage { get; set; }
}
}

View File

@ -16,6 +16,7 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json; using Newtonsoft.Json;
using Yavsc.Server.Helpers; using Yavsc.Server.Helpers;
using Microsoft.Extensions.OptionsModel; using Microsoft.Extensions.OptionsModel;
using Yavsc.Abstract.Manage;
namespace Yavsc.Services namespace Yavsc.Services
{ {
@ -98,9 +99,9 @@ namespace Yavsc.Services
return await NotifyEvent<HairCutQueryEvent>(registrationIds, ev); return await NotifyEvent<HairCutQueryEvent>(registrationIds, ev);
} }
public Task<string> SendEmailAsync(string username, string email, string subject, string message) public Task<EmailSentViewModel> SendEmailAsync(string username, string email, string subject, string message)
{ {
string messageId=null; EmailSentViewModel model = new EmailSentViewModel{ EMail = email };
try try
{ {
MimeMessage msg = new MimeMessage(); MimeMessage msg = new MimeMessage();
@ -123,14 +124,16 @@ namespace Yavsc.Services
smtpSettings.Port, smtpSettings.Port,
SecureSocketOptions.None); SecureSocketOptions.None);
sc.Send(msg); sc.Send(msg);
messageId = msg.MessageId; model.MessageId = msg.MessageId;
} }
} }
catch (Exception) catch (Exception ex)
{ {
return Task.FromResult<string>(null); model.Sent = false;
model.ErrorMessage = ex.Message;
return Task.FromResult<EmailSentViewModel>(model);
} }
return Task.FromResult(messageId); return Task.FromResult(model);
} }
public Task<bool> ValidateAsync(string purpose, string token, UserManager<ApplicationUser> manager, ApplicationUser user) public Task<bool> ValidateAsync(string purpose, string token, UserManager<ApplicationUser> manager, ApplicationUser user)

View File

@ -20,6 +20,7 @@ using Newtonsoft.Json;
namespace Yavsc.Controllers namespace Yavsc.Controllers
{ {
using Yavsc.Abstract.Manage;
using Yavsc.Helpers; using Yavsc.Helpers;
public class AccountController : Controller public class AccountController : Controller
@ -247,11 +248,11 @@ namespace Yavsc.Controllers
public async Task<IActionResult> SendEMailForConfirm() public async Task<IActionResult> SendEMailForConfirm()
{ {
var user = await _userManager.FindByIdAsync(User.GetUserId()); var user = await _userManager.FindByIdAsync(User.GetUserId());
ViewBag.EmailSent = await SendEMailForConfirmAsync(user); var model = await SendEMailForConfirmAsync(user);
return View("ConfirmEmailSent",user.Email); return View("ConfirmEmailSent",model);
} }
private async Task<string> SendEMailForConfirmAsync(ApplicationUser user) private async Task<EmailSentViewModel> SendEMailForConfirmAsync(ApplicationUser user)
{ {
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.Action("ConfirmEmail", "Account", var callbackUrl = Url.Action("ConfirmEmail", "Account",

View File

@ -1,4 +1,4 @@
@model string @model Yavsc.Abstract.Manage.EmailSentViewModel
@{ @{
ViewData["Title"] = "S'il vous plait, veuillez confirmer votre adresse e-mail"; ViewData["Title"] = "S'il vous plait, veuillez confirmer votre adresse e-mail";
@ -7,7 +7,7 @@
<h2>@ViewData["Title"].</h2> <h2>@ViewData["Title"].</h2>
<div> <div>
<p> <p>
Un message vient de vous être envoyé, à votre adresse e-mail ( @Model , id:@ViewBag.EmailSent ), Un message vient de vous être envoyé, à votre adresse e-mail ( @Model.Email , id:@Model.MessageId ),
Veuillez s&rsquo;il vous plait confirmer cette adresse de courrier en utilisant le lien hyper-texte qui s'y trouve. Veuillez s&rsquo;il vous plait confirmer cette adresse de courrier en utilisant le lien hyper-texte qui s'y trouve.
</p> </p>
</div> </div>

View File

@ -1 +1 @@
21-beta5 21-beta6