public IActionResult ProcessOfferCall(OfferCallDTO offerCallInfo) { _logger.LogInformation($"Offer Call: {offerCallInfo.ToString()}"); EmailSender emailService = new MailKitSender(provider.STMPConnection); string mailBodyInretnal = $"Заказ звонка\n\rИмя: {offerCallInfo.Name}\n\rНомер: {offerCallInfo.PhoneNumber}"; var taskInretnal = emailService.SendEmailAsync( new CredentialsDTO { Email = provider.STMPConnection.UserName, Name = provider.STMPConnection.CompanyName }, MailSubject, mailBodyInretnal); var ctsInretnal = new CancellationTokenSource(); try { _logger.LogInformation($"Sending OfferMail to MANAGER. {provider.STMPConnection.UserName}"); ctsInretnal.CancelAfter(provider.STMPConnection.TimeOut); taskInretnal.Wait(ctsInretnal.Token); _logger.LogInformation($"OfferMail sended to MANAGER. {provider.STMPConnection.UserName}"); } catch (OperationCanceledException ex) { _logger.LogError(ex, $"OfferMail Sending to MANAGER Timeout Exception. Connection problem. \nPURCHASE: {offerCallInfo.ToString()}"); return(NotFound("TimeoutException. " + ex.Message)); } catch (Exception ex) { _logger.LogError(ex, $"OfferMail Sending to MANAGER Exception. Something went wrong. \nPURCHASE: {offerCallInfo.ToString()}"); return(NotFound("Request exception. " + ex.Message)); } return(Ok()); }
public IActionResult ProcessPurchase(PurchaseDTO purchase) { _logger.LogInformation($"Purchase mail: {purchase.ToString()}"); EmailSender emailService = new MailKitSender(provider.STMPConnection); string mailBodyInretnal = string.Empty; try { mailBodyInretnal = _messageBuilder.Create(EmailType.Internal, purchase); } catch (Exception ex) { _logger.LogError(ex, $"Creating mail to MANAGER Exception. Something went wrong. \nPURCHASE: {purchase.ToString()}"); return(NotFound("Request exception. " + ex.Message)); } var taskInretnal = emailService.SendEmailAsync( new CredentialsDTO { Email = provider.STMPConnection.UserName, Name = provider.STMPConnection.CompanyName }, MailSubject, mailBodyInretnal); var ctsInretnal = new CancellationTokenSource(); try { _logger.LogInformation($"Sending mail to MANAGER. {provider.STMPConnection.UserName}"); ctsInretnal.CancelAfter(provider.STMPConnection.TimeOut); taskInretnal.Wait(ctsInretnal.Token); _logger.LogInformation($"Mail sended to MANAGER. {provider.STMPConnection.UserName}"); } catch (OperationCanceledException ex) { _logger.LogError(ex, $"Mail Sending to MANAGER Timeout Exception. Connection problem. \nPURCHASE: {purchase.ToString()}"); return(NotFound("TimeoutException. " + ex.Message)); } catch (Exception ex) { _logger.LogError(ex, $"Mail Sending to MANAGER Exception. Something went wrong. \nPURCHASE: {purchase.ToString()}"); return(NotFound("Request exception. " + ex.Message)); } if (string.IsNullOrEmpty(purchase.Credentials.Email)) { return(Ok()); } string mailBodyExternal = string.Empty; try { mailBodyExternal = _messageBuilder.Create(EmailType.External, purchase); } catch (Exception ex) { _logger.LogError(ex, $"Creating mail to USER Exception. Something went wrong. \nPURCHASE: {purchase.ToString()}"); return(NotFound("Request exception. " + ex.Message)); } var taskExternal = emailService.SendEmailAsync(purchase.Credentials, MailSubject, mailBodyExternal); var ctsExternal = new CancellationTokenSource(); try { _logger.LogInformation($"Sending mail to USER. {purchase.Credentials.Email}"); ctsExternal.CancelAfter(provider.STMPConnection.TimeOut); taskExternal.Wait(ctsExternal.Token); _logger.LogInformation($"Mail sended to USER. {purchase.Credentials.Email}"); } catch (OperationCanceledException ex) { _logger.LogError(ex, $"Mail Sending to USER Timeout Exception. Connection problem. \nPURCHASE: {purchase.ToString()}"); return(NotFound("TimeoutException. " + ex.Message)); } catch (Exception ex) { _logger.LogError(ex, $"Mail Sending to USER Exception. Something went wrong. \nPURCHASE: {purchase.ToString()}"); return(NotFound("Request exception. " + ex.Message)); } return(Ok()); }