Exemple #1
0
        public void TestEmailSend()
        {
            FastEmail email = new FastEmail();
            FastEmailConfiguration config = new FastEmailConfiguration(sender: "*****@*****.**", server: "10.164.34.27", password: "******", port: 25, enableSSL: false);

            email.Receipients = new System.Collections.Generic.List <string>()
            {
                "*****@*****.**"
            };
            email.CCList = new System.Collections.Generic.List <string>()
            {
                "*****@*****.**", "*****@*****.**"
            };
            email.Subject  = "Test Email";
            email.HTMLBody = "<div style=\"padding-top: 5px; padding-left: 5px; padding-right: 5px; padding-bottom: 5px; width: 100%; font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #666666; background-color: #e00000; \"><img width=\"200\" height=\"50\" src=\"https://dl.dropboxusercontent.com/u/97422769/Images/fastrack_brand.png\" alt=\"fastrack brand logo\" /></div>";

            try
            {
                _mailer = new SMTPEmail(config, email);
                _mailer.SendSynchronousEmail();
                Assert.IsTrue(true);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
Exemple #2
0
        public FastEmailConfiguration GetEmailConfiguration()
        {
            FastEmailConfiguration config = new FastEmailConfiguration();

            List <Configuration>           configs        = new List <Configuration>();
            GenericProcess <Configuration> genericProcess = new GenericProcess <Configuration>();

            int activeEmail = genericProcess.GetByID(FASTConstant.CONFIG_ACTIVEEMAIL).Value.ToInteger();

            if (activeEmail == 1)
            {
                config.MailPort      = genericProcess.GetByID(FASTConstant.CONFIG_MAILPORT).Value.ToInteger();
                config.MailServer    = genericProcess.GetByID(FASTConstant.CONFIG_MAILSERVER).Value;
                config.Password      = genericProcess.GetByID(FASTConstant.CONFIG_MAILPASSWORD).Value;
                config.SenderAddress = genericProcess.GetByID(FASTConstant.CONFIG_MAILUSER).Value;
                config.EnableSSL     = genericProcess.GetByID(FASTConstant.CONFIG_MAILSSL).Value.ToBoolean();
            }
            else
            {
                config.MailPort      = genericProcess.GetByID(FASTConstant.CONFIG_ALTMAILPORT).Value.ToInteger();
                config.MailServer    = genericProcess.GetByID(FASTConstant.CONFIG_ALTMAILSERVER).Value;
                config.Password      = genericProcess.GetByID(FASTConstant.CONFIG_ALTMAILPASSWORD).Value;
                config.SenderAddress = genericProcess.GetByID(FASTConstant.CONFIG_ALTMAILUSER).Value;
                config.EnableSSL     = genericProcess.GetByID(FASTConstant.CONFIG_ALTMAILSSL).Value.ToBoolean();
            }


            return(config);
        }
Exemple #3
0
        public SMTPEmail(FastEmailConfiguration configuration, FastEmail data)
        {
            XmlConfigurator.Configure();
            tracer.Info("Sending Email to : " + data.Receipients.ListToString());

            _mailServer = configuration.MailServer;
            _mailPort   = configuration.MailPort;
            _password   = BasicCrypto.DecryptString(configuration.Password);
            _enableSSL  = configuration.EnableSSL;
            _mailFrom   = configuration.SenderAddress;

            _emailData = data;
        }
Exemple #4
0
        public ActionResult Index()
        {
            ConfigurationProcess   process       = new ConfigurationProcess();
            FastEmailConfiguration configuration = process.GetEmailConfiguration();

            //Lets store the config in a session
            Session[FASTConstant.SESSION_EMAIL_CONFIG] = configuration;

            if (Request.IsAuthenticated)
            {
                //If authenticated, should go to the Dashboard. For now, lets assume that the Dashboard is the report page
                return(RedirectToAction("MyAssets", "Home"));
            }
            else
            {
                return(RedirectToAction("Login", "Authenticate"));
            }
        }
 public UserProcess()
 {
     XmlConfigurator.Configure();
     _emailConfig = configProcess.GetEmailConfiguration();
 }
Exemple #6
0
        public ActionResult UploadFile()
        {
            ExcelHelper excelHelp = new ExcelHelper();
            List <FixAssetExcelUploadModel> assets = new List <FixAssetExcelUploadModel>();
            BulkUpload           currentUpload     = new Common.BulkUpload();
            BulkUploadProcess    bulkProcess       = new BulkUploadProcess();
            AssetProcess         assetProcess      = new AssetProcess();
            EmployeeProcess      employeeProcess   = new EmployeeProcess();
            Employee             sender            = new Employee();
            ConfigurationProcess configProcess     = new ConfigurationProcess();

            FastEmailConfiguration emailConfig = configProcess.GetEmailConfiguration();

            StringBuilder uploadLog = new StringBuilder();

            string filename         = string.Empty;
            string completeFileName = string.Empty;

            //This is for the logging
            bulkProcess.UserID     = User.Identity.Name.ToInteger();
            configProcess.UserID   = User.Identity.Name.ToInteger();
            employeeProcess.UserID = User.Identity.Name.ToInteger();
            assetProcess.UserID    = User.Identity.Name.ToInteger();


            try
            {
                #region Get Request Files
                foreach (string upload in Request.Files)
                {
                    if (!(Request.Files[upload] != null && Request.Files[upload].ContentLength > 0))
                    {
                        continue;
                    }
                    string path = HttpContext.Server.MapPath("\\App_Data\\BulkUploads");
                    filename = Path.GetFileName(Request.Files[upload].FileName);

                    //check the filename and ensure its an xlsx file
                    if (String.Compare(filename.Substring(filename.Length - 4), "xlsx", true) != 0)
                    {
                        throw new Exception("Invalid file extension.");
                    }

                    //add the current time as unique indicator
                    filename = DateTime.Now.ToFileTime().ToString() + "_" + filename;

                    // If Upload folder is not yet existing, this code will create that directory.
                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }
                    completeFileName = Path.Combine(path, filename);
                    Request.Files[upload].SaveAs(completeFileName);
                }
                #endregion

                BulkUpload newFile = new BulkUpload()
                {
                    EmployeeID   = User.Identity.Name.ToInteger(),
                    FilePath     = filename,
                    TotalRecords = 0,
                    TotalInserts = 0,
                    RequestDate  = DateTime.Now,
                    Type         = FASTConstant.BULKIPLOAD_TYPE_ASSET
                };

                if (bulkProcess.Add(newFile) == FASTConstant.RETURN_VAL_SUCCESS)
                {
                    //get the current upload
                    currentUpload = bulkProcess.GetCurrentUpload(newFile.FilePath, newFile.EmployeeID);
                }

                if (currentUpload != null)
                {
                    #region Process the excel file
                    //Success! Lets process the file.
                    System.Data.DataTable fixAssetTable = new DataTable();

                    fixAssetTable = excelHelp.GetExcelDataTable(completeFileName, "SELECT * FROM [FixAsset$]");
                    fixAssetTable = excelHelp.ConvertToFixAssetTable(fixAssetTable);

                    if (fixAssetTable == null)
                    {
                        throw new Exception("The upload file contains null data.");
                    }

                    assets = fixAssetTable.ToList <Models.FixAssetExcelUploadModel>();
                    sender = employeeProcess.GetEmployeeByID(currentUpload.EmployeeID);

                    if (assets.Count > 0)
                    {
                        int totalInserts = 0;
                        currentUpload.TotalRecords = assets.Count;

                        bulkProcess.UpdateProcessingStep(currentUpload, FASTConstant.BULKUPLOAD_STATUS_INPROGRESS);

                        foreach (FixAssetExcelUploadModel asset in assets)
                        {
                            FixAsset tempAsset = new FixAsset()
                            {
                                AssetTag        = asset.AssetTag,
                                SerialNumber    = asset.SerialNumber,
                                Model           = asset.Model,
                                Brand           = asset.Brand,
                                AssetClassID    = asset.AssetClassID,
                                AssetTypeID     = asset.AssetTypeID,
                                AssetStatusID   = asset.AssetStatusID,
                                AcquisitionDate = asset.AcquisitionDate
                            };


                            if (assetProcess.Add(tempAsset) == FASTConstant.RETURN_VAL_SUCCESS)
                            {
                                totalInserts++;
                                uploadLog.AppendLine(String.Format("<p>{0} : {1} inserted.</p>", FASTConstant.SUCCESSFUL, asset.AssetTag));
                            }
                            else
                            {
                                uploadLog.AppendLine(String.Format("<p>{0} : {1} not inserted.</p>", FASTConstant.FAILURE, asset.AssetTag));
                            }
                        }

                        currentUpload.TotalInserts = totalInserts;
                        bulkProcess.UpdateProcessingStep(currentUpload, FASTConstant.BULKUPLOAD_STATUS_DONE);


                        //Send email to the requestor
                        FastEmail email = new FastEmail();
                        email.Receipients = new List <string>()
                        {
                            sender.EmailAddress
                        };
                        email.Subject  = FASTConstant.EMAIL_SIMPLE_SUBJECT.Replace("[XXX]", "Fix Asset Bulk Upload Result");
                        email.HTMLBody = FASTProcess.Helper.EmailHelper.GenerateHTMLBody(FASTProcess.Helper.EmailHelper.EmailType.BULK_UPLOAD);

                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_RECEIPIENT_NAME, sender.FirstName + " " + sender.LastName);
                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_BULKUPLOAD_INFO, bulkProcess.GenerateUploadinformationHTML(currentUpload));
                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_BULKUPLOAD_LOG, uploadLog.ToString());
                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_BULKUPLOAD_SUMMARY, bulkProcess.GenerateSummaryinformationHTML(currentUpload));

                        SMTPEmail emailSender = new SMTPEmail(emailConfig, email);
                        emailSender.SendEmail();
                    }
                    else
                    {
                        bulkProcess.UpdateProcessingStep(currentUpload, FASTConstant.BULKUPLOAD_STATUS_DONE);
                    }
                    #endregion
                }

                TempData["Result"]       = "SUCCESSFUL";
                TempData["Source"]       = "File Upload";
                TempData["ExtraMessage"] = "An email will be sent to you containing the results of the upload process.";
                TempData["Action"]       = "Index";
                TempData["Controller"]   = "FixAsset";

                return(View("~/Views/Shared/Result.cshtml"));
            }
            catch (Exception ex)
            {
                TempData["Result"]       = "FAILURE";
                TempData["Source"]       = "Fix Asset Bulk Upload";
                TempData["ExtraMessage"] = ex.Message;
                return(View("~/Views/Shared/Result.cshtml"));
            }
        }