/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A <see cref="Agatha.Common.Response"/></returns> public override Response Handle(SendC32Request request) { SendC32Response response = CreateTypedResponse(); Staff staff = Session.QueryOver <Staff> ().Where(s => s.Key == request.StaffKey).SingleOrDefault(); string fromAddress = staff.DirectAddressCredential.DirectAddress.Address; var fromDisplayName = staff.StaffProfile.StaffName.Complete; long patientKey = request.PatientKey; // Build Normative C32 Document string c32 = _builder.BuildC32Xml(patientKey, false); // Build Html Document representing the C32 string c32Html = CreateHtmlC32(c32); string body = request.Body; string toAddress = request.ToDirectEmail; var mailMessageBuilder = new MailMessageBuilder(); mailMessageBuilder .Compose(fromAddress, fromDisplayName, toAddress, string.Empty, request.Subject, body) .WithAttachment(c32, string.Format("{0}{1}", DateTime.Now.Ticks, ".xml")) .WithAttachment(c32Html, "Preview.html"); _mailMessageSender.Send(mailMessageBuilder.MailMessage); return(response); }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>Returns a Response object.</returns> public override Response Handle(SendDirectMessageRequest request) { var response = CreateTypedResponse(); var session = _sessionProvider.GetSession(); var info = _userInformationDtoFactory.CreateUserInformationDto(); var staff = session.QueryOver <Staff>().Where(s => s.Key == info.StaffKey).SingleOrDefault(); var fromAddress = staff.DirectAddressCredential.DirectAddress.Address; var fromDisplayName = staff.StaffProfile.StaffName.Complete; var mailMessageBuilder = new MailMessageBuilder(); mailMessageBuilder .Compose(fromAddress, fromDisplayName, request.ToDirectEmail, string.Empty, request.Subject, request.Body); if (request.AttachmentData != null) { mailMessageBuilder.WithAttachment(request.AttachmentData, request.AttachmentFileName); } _mailMessageSender.Send(mailMessageBuilder.MailMessage); return(response); }
protected virtual MailMessageSenderResult Transmit(MessageType messageType, MailMessage FilteredMsg) { // Create sender for the message type IMailMessageSender sender = MailMessageSenderFactory.CreateMessageSender(messageType, FilteredMsg.IsBulk); MailMessageSenderResult senderResult = sender.Send(FilteredMsg); return(senderResult); }
public async Task HandleAsync(Employee employee) { if (!await _validator.ValidateAsync(employee)) { return; } await _repository.InsertAsync(employee); await _unitOfWork.CommitAsync(); await _mailMessageSender.Send(employee); }
private static void SenderThreadMain() { for (; ;) { MessageContainer c = Dequeue(); if (c != null) { // Message is a retry the needs to be sent in the future if (c.SendTime > DateTime.Now) { Enqueue(c); Thread.Sleep(300); } else { try { // Create sender for this type of message IMailMessageSender sender = MailMessageSenderFactory.CreateMessageSender(c.msgType, c.msg.IsBulk); // If sender supports IRetryOnError, turn it off so we can retry it through the queue IRetryOnError senderRetryOnError = sender as IRetryOnError; bool senderRetryOnErrorEnabled = false; if (senderRetryOnError != null) { senderRetryOnErrorEnabled = senderRetryOnError.EnableRetryOnError; senderRetryOnError.EnableRetryOnError = false; } try { // Send message MailMessageSenderResult senderResult = sender.Send(c.msg); // TODO: add logging //Logger.Info("Send " + c.msgType + " message (" + c.msg.Subject + ") to " + c.msg.Recipients.ToString()+" using "+ // sender.GetType().FullName); } catch (Exception e) { // Catch errors and requeue the message to be resent later if (senderRetryOnErrorEnabled) { c.ErrorCount++; if (c.ErrorCount < senderRetryOnError.RetryOnErrorCount) { c.SendTime = DateTime.Now + new TimeSpan(0, 0, 10); Enqueue(c); //Logger.Error("Error sending message. Retry " + (c.ErrorCount - 1) + " of " + // senderRetryOnError.RetryOnErrorCount + ".", e); } //else // Logger.Error("Error sending message after " + senderRetryOnError.RetryOnErrorCount + // " retries. Message has been discarded.", e); } //else // Logger.Error("Error sending message. Message has been discarded (Retry was not available).", e); } } catch (Exception e) { //Logger.Error("Error creating message sender ("+c.msgType+". Message has been discarded.", e); } } } else { Thread.Sleep(500); } } }