public Error SendMSQOverrideEMail(CompanyModel company, UserModel sender, UserModel recipient, SalesOrderHeaderModel model) { var error = new Error(); // Send a message to the selected user, indicating that they have been // nominated as an approver of an MSQ override var message = new EMailMessage(sender, recipient, MessageTemplateType.MSQChangeNotification); message.AddProperty("ORDERNO", model.OrderNumber); message.AddProperty("SALESPERSON", sender.FullName); message.AddProperty("URL", GetConfigurationSetting("SiteHttp", "") + "/Sales/Sales/Edit?id=" + model.Id.ToString()); EMailService.EMailService emailService = new Evolution.EMailService.EMailService(db, company); error = emailService.SendEMail(message); if (!error.IsError) { var NotificationService = GetTaskManagerService(company); error = NotificationService.SendTask(Enumerations.MessageTemplateType.MSQChangeNotification, TaskType.MSQChangeNotification, LookupService.FindLOVItemsModel(company, LOVName.BusinessUnit) .Where(bu => bu.ItemText == "Sales") .FirstOrDefault(), recipient, model.CustomerId, message.Dict); } return(error); }
public void EmptyEMailQueueTest() { // Get a test user and test company var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser); EMailService.EMailService emailService = new EMailService.EMailService(db, testCompany); var sender = new UserModel { EMail = GetAppSetting("SenderAddress", "") }; UserModel recipient = new UserModel { EMail = GetAppSetting("RecipientAddress", "") }; // Create messages int numMsgs = 10; for (int i = 0; i < numMsgs; i++) { var error = new Error(); var message = new EMailMessage(sender, recipient, MessageTemplateType.TestMessage); message.AddProperty("MESSAGECONTENT", $"This message is {i + 1} of {numMsgs} and has been sent by an Evolution outomated test - please ignore."); error = emailService.SendEMail(message); Assert.IsTrue(!error.IsError, error.Message); } // Get the queue count int expected = 10, actual = emailService.GetQueueCount(); Assert.IsTrue(actual >= expected, $"Error: {actual} queue messages were found when {expected} were expected"); // Clean the queue emailService.EmptyEMailQueue(); // Chekc it again expected = 0; actual = emailService.GetQueueCount(); Assert.IsTrue(actual == expected, $"Error: {actual} queue messages were found when {expected} were expected"); }
public void SendEMailThroughTaskServiceTest() { // Get a test user and test company var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser); EMailService.EMailService emailService = new EMailService.EMailService(db, testCompany); MediaService.MediaService mediaService = new Evolution.MediaService.MediaService(db); var sender = new UserModel { EMail = GetAppSetting("SenderAddress", "") }; UserModel recipient = new UserModel { EMail = GetAppSetting("RecipientAddress", "") }; // Create messages, the first 10 without attachments, the rest with attachments int numMsgs = 20; for (int i = 0; i < numMsgs; i++) { var error = new Error(); var message = new EMailMessage(sender, recipient, MessageTemplateType.TestMessage); if (i >= 10) { message.AddProperty("MESSAGECONTENT", $"This message is {i + 1} of {numMsgs} and has been sent with an attachment by an Evolution outomated test - please ignore."); string tempFile = MediaService.MediaService.GetTempFile(".txt"); db.LogTestFile(tempFile); message.AddAttachment(tempFile, FileCopyType.Move); using (StreamWriter sw = new StreamWriter(tempFile)) { sw.WriteLine("Attachment " + (i - 9).ToString()); sw.WriteLine(""); sw.WriteLine(LorumIpsum()); } error = emailService.SendEMail(message); } else { message.AddProperty("MESSAGECONTENT", $"This message is {i + 1} of {numMsgs} and has been sent by an Evolution outomated test - please ignore."); error = emailService.SendEMail(message); } Assert.IsTrue(!error.IsError, error.Message); } if (GetAppSetting("EMailSendingServiceInTests", false)) { TaskService.TaskService ts = new TaskService.TaskService(db); var mailSender = ts.FindScheduledTaskModel(TaskName.MailSenderTask); Assert.IsTrue(mailSender != null, "Error: MailSender Scheduled Task not found"); var enabled = mailSender.Enabled; if (!enabled) { ts.EnableTask(mailSender, true); } //ts.RunTask(mailSender.Id, true); var mailSenderTask = new MailSenderTask(db); string[] args = null; mailSenderTask.Run(args); mailSender = ts.FindScheduledTaskModel(TaskName.MailSenderTask); Assert.IsTrue(mailSender != null, "Error: MailSender Scheduled Task not found"); ts.EnableTask(mailSender, enabled); } }
public Error SendPurchaseOrderToSupplier(int purchaseOrderHeaderTempId, UserModel sender, string pdfFile) { var error = new Error(); if (string.IsNullOrEmpty(sender.EMail)) { error.SetError(EvolutionResources.errInvalidSenderEMailAddress, "", (string.IsNullOrEmpty(sender.EMail) ? "" : sender.EMail), sender.FullName); } else { var poht = db.FindPurchaseOrderHeaderTemp(purchaseOrderHeaderTempId); if (poht == null) { error.SetError(EvolutionResources.errRecordError, "", "PurchaseOrderHeaderTemp", purchaseOrderHeaderTempId.ToString()); } else { var purchaseOrderHeaderId = (poht.OriginalRowId == null ? 0 : poht.OriginalRowId.Value); var poh = db.FindPurchaseOrderHeader(poht.OriginalRowId.Value); if (poh == null) { error.SetError(EvolutionResources.errRecordError, "", "PurchaseOrderHeader", purchaseOrderHeaderId.ToString()); } else if (poh.Supplier == null) { error.SetError(EvolutionResources.errCantSendOrderPurchaseOrderHasNoSupplier); } else if (string.IsNullOrEmpty(poh.Supplier.Email)) { error.SetError(EvolutionResources.errCantSendOrderSupplierHasNoEMail, "", poh.Supplier.Name); } else { // Attach the PDF to a note against the Purchase Order NoteService.NoteService noteService = new NoteService.NoteService(db); error = noteService.AttachNoteToPurchaseOrder(poh, sender, "Purchase Order Sent to Supplier", "", pdfFile.ToStringList(), FileCopyType.Copy); if (!error.IsError) { poh.DatePOSentToSupplier = DateTimeOffset.Now; db.InsertOrUpdatePurchaseOrderHeader(poh); poht.DatePOSentToSupplier = poh.DatePOSentToSupplier; db.InsertOrUpdatePurchaseOrderHeaderTemp(poht); // EMail the purchase order to the supplier var message = new EMailMessage(sender, MessageTemplateType.PurchaseOrderNotificationSupplier); var company = CompanyService.FindCompanyModel(poh.CompanyId); message.AddProperty("PURCHASEORDERNO", poh.OrderNumber.Value); message.AddProperty("COMPANYNAME", company.FriendlyName); message.AddProperty("USERNAME", sender.FullName); message.AddProperty("EMAIL", sender.EMail); message.AddRecipient(poh.Supplier.Email); message.AddAttachment(pdfFile, FileCopyType.Move); EMailService.EMailService emailService = new Evolution.EMailService.EMailService(db, company); error = emailService.SendEMail(message); } } } } return(error); }
private Error processPurchaseOrder(PurchaseOrderHeader poh, FileTransferConfigurationModel template, FileRecipient fileRecipient) { var error = new Error(); // Load the template configuration file string configFile = getTemplateFileName(template), tempFile = "", zipFile = ""; XElement doc = XElement.Load(configFile); var file = doc.Element("File"); error = createPurchaseOrderDataFile(poh, file, ref tempFile); if (!error.IsError) { // Check if the file is compressed individually and sent bool bCompress = file.Attribute("CompressFile").Value.ParseBool(); if (bCompress) { // File is to be compressed zipFile = tempFile.ChangeExtension(".zip"); error = Zip.ZipFile(tempFile, zipFile); if (error.IsError) { FileManagerService.FileManagerService.DeleteFile(zipFile); } else { tempFile = zipFile; } } bool bDelTempFile = true; if (!error.IsError) { if (file.Attribute("FTPFile").Value.ParseBool()) { // Copy the file to the FTP pickup folder error = moveFileToFTPFolder(tempFile, template.SourceFolder, poh.OrderNumber + (bCompress ? ".zip" : ".txt")); } if (!error.IsError && file.Attribute("EMailFile").Value.ParseBool()) { // Queue the file to be sent as an email var company = CompanyService.FindCompanyModel(poh.CompanyId); var purchaser = MembershipManagementService.FindUserModel(poh.SalespersonId.Value); string email = ""; if (fileRecipient == FileRecipient.FreightForwarder) { var fforwarder = LookupService.FindFreightForwarderModel(poh.FreightForwarderId.Value); if (string.IsNullOrEmpty(fforwarder.Email)) { error.SetError(EvolutionResources.errCantSendEMailToBlankFreightForwarderAddress); } else { email = fforwarder.Email; } } else { error.SetError(EvolutionResources.errEMailingWarehouseNotSupported); } if (!error.IsError) { var recipient = new UserModel { EMail = email }; var message = new EMailMessage(purchaser, recipient, MessageTemplateType.PurchaseOrderNotificationFF); EMailService(company).AddOrganisationDetails(message.Dict); EMailService().AddUserDetails(purchaser, message.Dict); message.AddProperty("PURCHASEORDERNO", poh.OrderNumber.Value); message.AddAttachment(tempFile); error = EMailService().SendEMail(message); if (!error.IsError) { bDelTempFile = false; } } } } if (bDelTempFile) { FileManagerService.FileManagerService.DeleteFile(tempFile); } } return(error); }
void ScanLogsForErrors() { LogSeverity severity = (LogSeverity)GetTaskParameter("ReportErrorsAboveSeverity", (int)LogSeverity.Severe); DateTime lastRun = GetTaskParameter("LastRun", DateTime.Now); SetTaskParameter("LastRun", DateTime.Now); string systemErrors = "", taskErrors = ""; foreach (var logRecord in _db.FindLogsAfter(lastRun, severity)) { systemErrors += "<tr><td style=\"width:120px\">Date:</td><td style=\"width:auto\">" + logRecord.LogDate.ToString() + "</td></tr>\r\n"; systemErrors += "<tr><td style=\"vertical-align:top\">URL:</td><td>" + logRecord.Url + "</td></tr>\r\n"; systemErrors += "<tr><td style=\"vertical-align:top\">Error:</td><td>" + logRecord.Message + "</td></tr>\r\n"; systemErrors += "<tr><td style=\"vertical-align:top\">Stack Trace:</td><td>" + logRecord.StackTrace + "</td></tr>\r\n"; } foreach (var logRecord in _db.FindScheduledTaskLogsAfter(lastRun, severity)) { taskErrors += "<tr>"; taskErrors += "<td style=\"width:120px\">" + logRecord.LogDate.ToString() + "</td>"; taskErrors += "<td style=\"vertical-align:top\">" + logRecord.ScheduledTask.TaskName + "</td>"; taskErrors += "<td style=\"vertical-align:top\">" + logRecord.Message; if (!string.IsNullOrEmpty(logRecord.StackTrace)) { taskErrors += "<br/><br/>" + logRecord.StackTrace; } taskErrors += "</td>"; taskErrors += "</tr>\r\n"; } if (!string.IsNullOrEmpty(systemErrors) || !string.IsNullOrEmpty(taskErrors)) { if (string.IsNullOrEmpty(systemErrors)) { systemErrors = "<tr><td>None></td><td></td></tr>"; } if (string.IsNullOrEmpty(taskErrors)) { taskErrors = "<tr><td>None></td><td></td><td></td></tr>"; } string groupName = GetTaskParameter("SendErrorsToGroup", ""); UserGroup userGroup = _db.FindUserGroup(groupName); if (userGroup == null) { WriteTaskLog($"Error: User group '{groupName}' could not be found!"); } else { var sender = new UserModel { EMail = GetTaskParameter("SenderEMail", "*****@*****.**") }; var message = new EMailMessage(sender, MessageTemplateType.SystemError); message.AddProperty("SYSTEMERRORS", systemErrors); message.AddProperty("TASKERRORS", taskErrors); foreach (var user in _db.FindUserGroupUsers(userGroup)) { var userModel = Mapper.Map <User, UserModel>(user); message.AddRecipient(userModel); } EMailService.EMailService emailService = new EMailService.EMailService(_db); emailService.SendEMail(message); } } }