Example #1
0
        public void certemail(int intUserID, int intCourseID, int intProfileID)
        {
            int orgid;

            BusinessServices.User objUser = new BusinessServices.User();
            DataTable             dtUser  = objUser.GetUser(intUserID);

            Int32.TryParse(dtUser.Rows[0]["OrganisationID"].ToString(), out orgid);
            string username = dtUser.Rows[0]["UserName"].ToString();

            BusinessServices.AppConfig objAppConfig = new BusinessServices.AppConfig();
            DataTable dtbAppConfig = objAppConfig.GetList();
            string    strHostname  = HttpContext.Current.Request.Url.Authority.ToString();
            bool      isSSL        = bool.Parse(dtbAppConfig.Select("Name='SSL'")[0]["Value"].ToString());
            string    strUrl       = null;

            if (strHostname.ToLower().Equals("127.0.0.2"))
            {
                strUrl = "https://" + strHostname;
            }
            else
            {
                strUrl = "http://" + strHostname;
            }
            strUrl = "https://" + strHostname;
            //WriteErrorLog(strUrl.ToString());
            OrganisationConfig objOrgConfig = new OrganisationConfig();
            string             strCss       = objOrgConfig.GetOne(orgid, "css");

            string pdfFileName = "cert_" + username + "_" + intCourseID.ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
            bool   status      = HtmlToPdf.WKHtmlToPdf(strUrl + @"/Certificate.aspx?courseid=" + intCourseID + "&profileid=" + intProfileID + "&userid=" + intUserID + "&orgid=" + orgid + "&css=" + strCss, pdfFileName);
            string filename    = "";

            if (status)
            {
                filename = HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["WorkingFolder"]) + "\\" + pdfFileName;
            }
            else
            {
                ErrorLog objError = new ErrorLog(new Exception("Course completion certificate"), ErrorLevel.Medium, "DefaultQuiz.cs", "GenerateCourseCompletionCertificate", "Course completion certificate generation failed: " + pdfFileName);
            }


            sendCertEmail(intUserID, intCourseID, orgid, filename);

            try
            {
                FileInfo fileinfo = new FileInfo(filename);
                if (fileinfo.Exists)
                {
                    File.Delete(filename);
                }
            }
            catch (Exception e)
            {
                ErrorLog objError = new ErrorLog(e, ErrorLevel.Medium, "DefaultQuiz.cs", "DeleteCourseCompletionCertificate", "Course completion certificate deletion failed: " + pdfFileName);
            }
        }
        private void setButtonLabel()
        {
            try
            {
                String[]          strArr;
                ServiceController scSendMail = null;

                BusinessServices.AppConfig ac = new BusinessServices.AppConfig();

                DataTable dt = ac.getMailServices();


                foreach (DataRow dr in dt.Rows)
                {
                    strArr = dr.ItemArray[1].ToString().Split(';');

                    if (dr.ItemArray[0].Equals("MailService_SendMail"))
                    {
                        try
                        {
                            scSendMail = new ServiceController(strArr[1], strArr[0]);
                        }
                        catch (Exception e)
                        {
                            btnServiceToggle.Text = "- No Service Permissions -";
                        }
                    }
                }

                if (scSendMail.Status != ServiceControllerStatus.Stopped)
                {
                    btnServiceToggle.Text = ResourceManager.GetString("btnStopServices");
                }
                else
                {
                    btnServiceToggle.Text = ResourceManager.GetString("btnStartServices");
                }
            }
            catch (Exception e)
            {
                ErrorHandler.ErrorLog el = new ErrorHandler.ErrorLog(e, ErrorLevel.High, "Service Control", "No Permissions to access", "Please use subinacl.exe to grant permissions");
            }
        }
Example #3
0
		private string GetEmailBody(EmailReportType emailReportType)
		{
			OrganisationConfig objOrgConfig = new OrganisationConfig();
			BusinessServices.AppConfig objAppConfig = new BusinessServices.AppConfig();
			string strEmailBody="";

			switch (emailReportType)
			{
				case EmailReportType.Email_Incomplete_CPD_User:
				{
					strEmailBody = objOrgConfig.GetOne(UserContext.UserData.OrgID,"Email_Incomplete_CPD_User");
					break;
				}
				
				case EmailReportType.Email_Incomplete_CPD_Administrator:
				{
					strEmailBody = objOrgConfig.GetOne(UserContext.UserData.OrgID,"Email_Incomplete_CPD_Administrator");
					break;
				}
			} // switch

			
			// Get the application conffiguration details
			DataTable dtbAppConfig = objAppConfig.GetList();

			// Setup the email body
			foreach (DataRow drwAppConfig in dtbAppConfig.Rows)
			{
				if (drwAppConfig.ItemArray[0].ToString().ToUpper()=="APPNAME")
				{
					strEmailBody = strEmailBody.Replace("%APP_NAME%",drwAppConfig.ItemArray[1].ToString());
				}
			}
			strEmailBody = strEmailBody.Replace("<BR>",Environment.NewLine);
			return (strEmailBody);
		}
        protected void btnServiceToggle_Click(object sender, EventArgs e)
        {
            try
            {
                BusinessServices.AppConfig ac = new BusinessServices.AppConfig();
                BusinessServices.Email     em = new BusinessServices.Email();

                DataTable dt = ac.getMailServices();

                String[] strArr;

                ServiceController scQueueMail    = null;
                ServiceController scQueueReports = null;
                ServiceController scSendMail     = null;


                foreach (DataRow dr in dt.Rows)
                {
                    strArr = dr.ItemArray[1].ToString().Split(';');

                    if (dr.ItemArray[0].Equals("MailService_QueueMail"))
                    {
                        scQueueMail = new ServiceController(strArr[1], strArr[0]);
                    }
                    else if (dr.ItemArray[0].Equals("MailService_QueueReports"))
                    {
                        scQueueReports = new ServiceController(strArr[1], strArr[0]);
                    }
                    else if (dr.ItemArray[0].Equals("MailService_SendMail"))
                    {
                        scSendMail = new ServiceController(strArr[1], strArr[0]);
                    }
                }

                //String username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;// used for debugging

                // if its stopped then start it
                if (scSendMail.Status == ServiceControllerStatus.Stopped)
                {
                    em.purgeAutoEmails();

                    // set the send mail flag to allow emails to be sent
                    ac.Update("SEND_AUTO_EMAILS", "YES");

                    scSendMail.Start();
                    scSendMail.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 10));
                    scSendMail.Refresh();
                }
                // if its started then stop it
                else if (scSendMail.Status == ServiceControllerStatus.Running)
                {
                    em.purgeAutoEmails();

                    // set the send mail flag to stop emails from being sent
                    ac.Update("SEND_AUTO_EMAILS", "NO");

                    // restart report queuing
                    restartService(scQueueReports);

                    scSendMail.Stop();
                    scSendMail.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 10));
                    scSendMail.Refresh();

                    // restart mail queuing service
                    restartService(scQueueMail);
                }

                //username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                setButtonLabel();
            }
            catch (Exception ex)
            {
                ErrorHandler.ErrorLog el = new ErrorHandler.ErrorLog(ex, ErrorLevel.High, "Service Control", "Panic button pressed", ex.Message);
            }
        }
Example #5
0
        /// <summary>
        /// Compiles the list of users to which the email should be sent,
        /// and attempts to send it to that list + anyone on the CC list
        /// + the current user.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSendEmail_Click(object sender, System.EventArgs e)
        {
            string strUnitIDs = "";
            string strUserIDs = "";

            lblError.Text = "";

            try
            {
                // Get selected units
                BusinessServices.Unit objUnit = new  BusinessServices.Unit();
                string[] astrUnitIDs          = astrUnitIDs = objUnit.ReturnAdministrableUnitsByUserID(UserContext.UserID, UserContext.UserData.OrgID, trvUnitsSelector.GetSelectedValues());
                foreach (string strUnit in astrUnitIDs)
                {
                    strUnitIDs += strUnit + ",";
                }
                if (strUnitIDs.Length > 0)
                {
                    strUnitIDs = strUnitIDs.Substring(0, strUnitIDs.Length - 1);
                }

                // Get users
                DataTable dtbResults = new Email().GetUsersToEmail(UserContext.UserData.OrgID, strUnitIDs);
                foreach (DataRow drwUser in dtbResults.Rows)
                {
                    strUserIDs += drwUser.ItemArray[0].ToString() + ",";
                }
                if (strUserIDs.Length > 0)
                {
                    strUserIDs = strUserIDs.Substring(0, strUserIDs.Length - 1);
                }

                // Validate that the user has a valid recipient, subject and body.
                if (strUserIDs.Length > 0 && this.txtEmailSubject.Text.Length > 0 && this.txtEmailBody.Text.Length > 0)
                {
                    // Config
                    BusinessServices.AppConfig objAppConfig = new BusinessServices.AppConfig();
                    DataTable dtbAppConfig = objAppConfig.GetList();
                    this.lblError.Text = "";

                    // Email setup
                    BusinessServices.User objUser = new BusinessServices.User();
                    DataTable             dtbCurrentUserDetails = objUser.GetUser(UserContext.UserID);
                    string strEmailFromName         = dtbCurrentUserDetails.Rows[0]["FirstName"].ToString() + " " + dtbCurrentUserDetails.Rows[0]["LastName"].ToString();
                    string strEmailFromEmail        = dtbCurrentUserDetails.Rows[0]["Email"].ToString();
                    string strEmailSubject          = this.txtEmailSubject.Text;
                    string strUsers                 = "\n\nSent To:";
                    BusinessServices.Email objEmail = new BusinessServices.Email();

                    // target users
                    string    strEmailToName    = "";
                    string    strEmailToEmail   = "";
                    DataTable dtbEmailAddresses = objUser.GetEmails(strUserIDs);
                    foreach (DataRow drwEmailAddress in dtbEmailAddresses.Rows)
                    {
                        strEmailToEmail = drwEmailAddress.ItemArray[3].ToString();
                        strEmailToName  = drwEmailAddress.ItemArray[0].ToString() + " " + drwEmailAddress.ItemArray[1].ToString();
                        int intUserId = Int32.Parse(drwEmailAddress.ItemArray[1].ToString());
                        objEmail.SetEmailBody(this.txtEmailBody.Text, intUserId, "", "", "", "", "", "", "", "");
                        strEmailSubject = objEmail.emailHeaderSub(strEmailSubject);
                        objEmail.SendEmail(strEmailToEmail, strEmailToName, strEmailFromEmail, strEmailFromName, null, null, strEmailSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, intUserId);

                        // accumulate user list to append to current user email
                        strUsers += "\n\t" + strEmailToName;
                    }

                    // CC list.
                    string strEmailCCName = "";
                    strUsers += "\n\nCC:";
                    foreach (string addr in this.txtCC.Text.Split(new char[] { ',', ';' }))
                    {
                        string strEmailCCEmail = addr.Trim();
                        if (strEmailCCEmail != "")
                        {
                            try
                            {
                                objEmail.SendEmail(strEmailCCEmail, strEmailCCName, strEmailFromEmail, strEmailFromName, null, null, strEmailSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, 0);
                                strUsers += "\n\t" + strEmailCCEmail;
                            }
                            catch (Exception)
                            {
                                objEmail.setCCSendError(strEmailCCEmail);
                                objEmail.SendEmail(strEmailFromEmail, strEmailFromName, strEmailFromEmail, strEmailFromName, null, null, "Error sending mail to CC recipient", ApplicationSettings.MailServer, UserContext.UserData.OrgID, UserContext.UserID);
                            }
                        }
                    }

                    // copy to Current user
                    objEmail.setUserCopyEmailBody(this.txtEmailBody.Text + strUsers);
                    objEmail.SendEmail(strEmailFromEmail, strEmailFromName, strEmailFromEmail, strEmailFromName, null, null, strEmailSubject, ApplicationSettings.MailServer, UserContext.UserData.OrgID, UserContext.UserID);

                    this.plhEditEmail.Visible = false;
                    this.plhComplete.Visible  = true;
                }
                else
                {
                    lblError.Text          = ResourceManager.GetString("lblError.OneRecip");         //"To send an email you must have at least one recipient, an email subject and an email body.";
                    this.lblError.CssClass = "WarningMessage";
                }
            }
            catch (Exception ex)
            {
                //Catch and throw error
                ErrorLog objError = new ErrorLog(ex, ErrorLevel.High, "EmailUsers.aspx.cs", "btnSendEmail_Click", "General error occurred attempting to send email");
                throw (ex);
            }
        }