public ActionResult Notify(String responseId)
        {
            int userId = GetIntSessionValue(UserSession.Key.UserId);

            //Get current user info
            int currentOrgId = GetIntSessionValue(UserSession.Key.SelectedOrgId);
            var userInfo     = _securityFacade.GetUserInfo(userId);
            //Get Organization admin info
            var             surveyAnswerDTO = GetSurveyAnswer(responseId, GetStringSessionValue(UserSession.Key.RootFormId));
            SurveyInfoModel surveyInfoModel = GetSurveyInfo(surveyAnswerDTO.SurveyId);

            var OwnerInfo = _securityFacade.GetUserInfo(surveyAnswerDTO.FormOwnerId);

            var email = new Email();

            email.To = new List <string>();
            email.To.Add(OwnerInfo.User.EmailAddress);
            email.From = EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailFrom);
            //email.Subject = "Record locked notification.";
            //email.Body = "A user was unable to edit/delete a Epi Info™ Cloud Enter recored. \n \n Please login to Epi Info™ Cloud Enter system to Unlock this record.\n \n Below are the needed info to unlock the record.\n \n Response id: " + responseId + "\n\n User email: " + userInfo.User.EmailAddress + "\n\n";
            email.Subject = ResourceProvider.GetResourceString(ResourceNamespaces.EmailMessages, EmailResourceKeys.RecordLocked_Subject);
            email.Body    = string.Format(ResourceProvider.GetResourceString(ResourceNamespaces.EmailMessages, EmailResourceKeys.RecordLocked_Body)
                                          , responseId, userInfo.User.EmailAddress);

            var success = EmailHandler.SendMessage(email);

            return(Json(1));
        }
        public JsonResult Notify(string emailAddress, string redirectUrl, string surveyName, string passCode, string EmailSubject)
        {
            try
            {
                var email = new Email();
                email.Body    = redirectUrl + " and Pass Code is: " + passCode;
                email.From    = EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailFrom).ToString();
                email.Subject = "Link for Survey: " + surveyName;// EmailSubject;
                List <string> tempList = new List <string>();
                tempList.Add(emailAddress);
                email.To = tempList;

                if (EmailHandler.SendMessage(email))
                {
                    return(Json(true));
                }
                else
                {
                    return(Json(false));
                }
            }
            catch (Exception ex)
            {
                return(Json(false));
            }
        }
        public JsonResult Notify(string emailAddress, string emailSubject)
        {
            string message = "";

            try
            {
                var email = new Email();
                email.Body    = "Test email From EWE System.";
                email.From    = EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailFrom);
                email.Subject = emailSubject;

                List <string> tempList = new List <string>();
                tempList.Add(emailAddress);
                email.To = tempList;
                message  = EmailHandler.SendNotification(email);
                if (message.Contains("Success"))
                {
                    return(Json(true));
                }
                else
                {
                    return(Json(message));
                }
            }
            catch (Exception ex)
            {
                return(Json(message));
            }
        }
        /// <summary>
        /// the following method takes email and responseUrl as argument and email redirection url to the user
        /// </summary>
        /// <param name="emailAddress">email address for sending message (email is NOT saved)</param>
        /// <param name="redirectUrl">url for resuming the saved survey</param>
        /// <param name="surveyName">Name of the survey</param>
        /// <param name="passCode"> Code for accessing an unfinished survey </param>
        /// <returns></returns>


        public static bool SendMessage(Email Email)
        {
            try
            {
                bool isAuthenticated = false;
                bool isUsingSSL      = false;
                int  smptPort        = 25;

                // App Config Settings:
                // EMAIL_USE_AUTHENTICATION [ True | False ] default is False
                // EMAIL_USE_SSL [ True | False] default is False
                // SMTP_HOST [ url or ip address of smtp server ]
                // SMTP_PORT [ port number to use ] default is 25
                // EMAIL_FROM [ email address of sender and authenticator ]
                // EMAIL_PASSWORD [ password of sender and authenticator ]


                isAuthenticated = EmailAppSettings.GetBoolValue(EmailAppSettings.Key.EmailUseAuthentication);

                isUsingSSL = EmailAppSettings.GetBoolValue(EmailAppSettings.Key.EmailUseSSL);

                smptPort = EmailAppSettings.GetIntValue(EmailAppSettings.Key.SmtpPort);

                MailMessage message = new MailMessage();
                foreach (string item in Email.To)
                {
                    message.To.Add(item);
                }

                message.Subject = Email.Subject;

                var userName = EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailUserName);
                message.From = new MailAddress(EmailAppSettings.GetStringValue(EmailAppSettings.Key.LoggingAdminEmailAddress));
                var smtpHost = EmailAppSettings.GetStringValue(EmailAppSettings.Key.SmtpHost);
                message.Body = Email.Body;
                SmtpClient smtp = new SmtpClient(smtpHost, smptPort);

                var passWord = EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailPassword);

                if (isAuthenticated)
                {
                    smtp.Credentials = new System.Net.NetworkCredential(userName, passWord);
                }

                smtp.EnableSsl      = isUsingSSL;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

                smtp.Send(message);

                return(true);
            }
            catch (System.Exception ex)
            {
                return(false);
            }
        }
        /// <summary>
        /// the following method takes email and responseUrl as argument and email redirection url to the user
        /// </summary>
        /// <param name="emailAddress">email address for sending message (email is NOT saved)</param>
        /// <param name="redirectUrl">url for resuming the saved survey</param>
        /// <param name="surveyName">Name of the survey</param>
        /// <param name="passCode"> Code for accessing an unfinished survey </param>
        /// <returns></returns>
        public static bool SendMessage(string emailAddress, string redirectUrl, string surveyName, string passCode, string EmailSubject)
        {
            try
            {
                bool isAuthenticated = false;
                bool isUsingSSL      = false;
                int  SMTPPort        = 25;

                // App Config Settings:
                // EMAIL_USE_AUTHENTICATION [ True | False ] default is False
                // EMAIL_USE_SSL [ True | False] default is False
                // SMTP_HOST [ url or ip address of smtp server ]
                // SMTP_PORT [ port number to use ] default is 25
                // EMAIL_FROM [ email address of sender and authenticator ]
                // EMAIL_PASSWORD [ password of sender and authenticator ]


                isAuthenticated = EmailAppSettings.GetBoolValue(EmailAppSettings.Key.EmailUseAuthentication);
                isUsingSSL      = EmailAppSettings.GetBoolValue(EmailAppSettings.Key.EmailUseSSL);
                SMTPPort        = EmailAppSettings.GetIntValue(EmailAppSettings.Key.SmtpPort);

                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                message.To.Add(emailAddress);
                message.Subject = EmailSubject;      // "Link for Survey: " + surveyName;
                message.From    = new System.Net.Mail.MailAddress(EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailFrom));
                message.Body    = redirectUrl + " and Pass Code is: " + passCode;
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(EmailAppSettings.GetStringValue(EmailAppSettings.Key.SmtpHost));
                smtp.Port = SMTPPort;

                if (isAuthenticated)
                {
                    smtp.Credentials = new System.Net.NetworkCredential(EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailFrom), EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailPassword));
                }

                smtp.EnableSsl = isUsingSSL;

                smtp.Send(message);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        private bool SendEmail(Email email, EmailCombinationEnum Combination)
        {
            switch (Combination)
            {
            case EmailCombinationEnum.InsertOrganization:
                email.Subject = "An Epi Info Cloud Data Capture account has been created for your organization.";

                break;

            default:
                break;
            }

            email.Body = email.Body.ToString();
            //+" \n \nPlease click the link below to launch Epi Cloud Data Capture. \n" + AppSettings.GetStringValue(AppSettings.Key.BaseURL) + "\n\nThank you."; //email.Body.ToString() + " \n \n" + AppSettings.GetStringValue(AppSettings.Key.BaseURL);
            email.From = EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailFrom);

            return(Epi.Web.Enter.Common.Email.EmailHandler.SendMessage(email));
        }
Ejemplo n.º 7
0
        private bool SendEmail(Email email, EmailCombinationEnum combination)
        {
            //   Epi.Common.Email.Email Email = new Web.Common.Email.Email();

            switch (combination)
            {
            case EmailCombinationEnum.ResetPassword:
                //email.Subject = "Your Epi Info Cloud Enter Password";
                //email.Body = string.Format("You recently accessed our Forgot Password service for Epi Info™ Cloud Enter. \n \n Your new temporary password is: {0}\n \n If you have not accessed password help, please contact the administrator. \n \nLog in with your temporary password. You will then be asked to create a new password.", email.Password);
                email.Subject = ResourceProvider.GetResourceString(ResourceNamespaces.EmailMessages, EmailResourceKeys.ResetPassword_Subject);
                email.Body    = string.Format(ResourceProvider.GetResourceString(ResourceNamespaces.EmailMessages, EmailResourceKeys.ResetPassword_Body), email.Password);
                break;

            case EmailCombinationEnum.PasswordChanged:
                //email.Subject = "Your Epi Info Cloud Enter Password has been updated";
                //email.Body = "You recently updated your password for Epi Info™ Cloud Enter. \n \n If you have not accessed password help, please contact the administrator for you organization. \n \n ";
                email.Subject = ResourceProvider.GetResourceString(ResourceNamespaces.EmailMessages, EmailResourceKeys.PasswordChanged_Subject);
                email.Body    = ResourceProvider.GetResourceString(ResourceNamespaces.EmailMessages, EmailResourceKeys.PasswordChanged_Body);
                break;

            case EmailCombinationEnum.UpdateUserInfo:
                //email.Subject = "Your Epi Info Cloud Enter Account info has been updated";
                //email.Body = " You account info has been updated in Epi Info™ Cloud Enter system.";
                email.Subject = ResourceProvider.GetResourceString(ResourceNamespaces.EmailMessages, EmailResourceKeys.UpdateUserInfo_Subject);
                email.Body    = ResourceProvider.GetResourceString(ResourceNamespaces.EmailMessages, EmailResourceKeys.UpdateUserInfo_Body);
                break;

            case EmailCombinationEnum.InsertUser:
                //email.Subject = "An Epi Info Cloud Enter account has been created for your organization.";
                email.Subject = ResourceProvider.GetResourceString(ResourceNamespaces.EmailMessages, EmailResourceKeys.InsertUser_Subject);
                break;

            default:
                break;
            }

            //email.Body = email.Body.ToString() + " \n \nPlease click the link below to launch Epi Cloud Enter. \n" + AppSettings.GetStringValue(AppSettings.Key.BaseURL) + "\nThank you.";
            email.From = EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailUserName);

            return(EmailHandler.SendMessage(email));
        }
        /// <summary>
        /// the following method sends email messages from loggin errors
        /// </summary>
        /// <param name="emailAddress">email address for sending message (email is NOT saved)</param>
        /// <param name="pSubjectLine">subject text</param>
        /// <param name="pMessage">Message body text</param>
        /// <returns></returns>
        //public static bool SendLogMessage(string emailAddress, string pSubjectLine, Exception exc, HttpContextBase Context = null)
        public static bool SendLogMessage(Exception exc, HttpContextBase Context = null)
        {
            try
            {
                bool   isAuthenticated     = false;
                bool   isUsingSSL          = false;
                int    SMTPPort            = 25;
                string AdminEmailAddress   = "";
                bool   IsEmailNotification = false;
                // App Config Settings:
                // EMAIL_USE_AUTHENTICATION [ True | False ] default is False
                // EMAIL_USE_SSL [ True | False] default is False
                // SMTP_HOST [ url or ip address of smtp server ]
                // SMTP_PORT [ port number to use ] default is 25
                // EMAIL_FROM [ email address of sender and authenticator ]
                // EMAIL_PASSWORD [ password of sender and authenticator ]
                string pMessage;

                pMessage = "Exception Message:\n" + exc.Message + "\n\n\n";
                if (Context != null)
                {
                    pMessage += "Exception Timestamp:\n" + Context.Timestamp + "\n\n\n"
                                + "Request Path:\n " + (Context.Request).Path + "\n\n\n"
                                + "Request Method:\n" + (Context.Request).HttpMethod + "\n\n\n";
                }
                pMessage += "Inner Exception :\n" + exc.InnerException + ";" +
                            "Exception StackTrace:\n" + exc.StackTrace + "\n\n\n";

                if (Context != null && !string.IsNullOrEmpty(Context.Session[UserSession.Key.UserFirstName].ToString()))
                {
                    pMessage += "Logged in User: \n" + Context.Session[UserSession.Key.UserFirstName].ToString() + " " + Context.Session[UserSession.Key.UserLastName].ToString() + "\n\n\n";;
                    pMessage += "Form Id: \n" + Context.Session[UserSession.Key.RootFormId] + "\n\n\n";;
                    pMessage += "Response Id: \n" + Context.Session[UserSession.Key.RootResponseId] + "\n\n\n";;
                }

                AdminEmailAddress = EmailAppSettings.GetStringValue(EmailAppSettings.Key.LoggingAdminEmailAddress);

                IsEmailNotification = EmailAppSettings.GetBoolValue(EmailAppSettings.Key.LoggingSendEmailNotification);

                isAuthenticated = EmailAppSettings.GetBoolValue(EmailAppSettings.Key.EmailUseAuthentication);

                isUsingSSL = EmailAppSettings.GetBoolValue(EmailAppSettings.Key.EmailUseSSL);

                SMTPPort = EmailAppSettings.GetIntValue(EmailAppSettings.Key.SmtpPort);

                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                //message.To.Add(emailAddress);
                message.To.Add(AdminEmailAddress);
                message.Subject = EmailAppSettings.GetStringValue(EmailAppSettings.Key.LoggingEmailSubject);
                message.From    = new System.Net.Mail.MailAddress(EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailFrom));
                message.Body    = pMessage;
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(EmailAppSettings.GetStringValue(EmailAppSettings.Key.SmtpHost));
                smtp.Port = SMTPPort;

                if (isAuthenticated)
                {
                    smtp.Credentials = new System.Net.NetworkCredential(EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailFrom), EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailPassword));
                }


                smtp.EnableSsl = isUsingSSL;

                if (IsEmailNotification)
                {
                    smtp.Send(message);
                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public static string SendNotification(Email Email)
        {
            try
            {
                bool isAuthenticated = false;
                bool isUsingSSL      = false;
                int  smtpPort        = 25;

                // App Config Settings:
                // EMAIL_USE_AUTHENTICATION [ True | False ] default is False
                // EMAIL_USE_SSL [ True | False] default is False
                // SMTP_HOST [ url or ip address of smtp server ]
                // SMTP_PORT [ port number to use ] default is 25
                // EMAIL_FROM [ email address of sender and authenticator ]
                // EMAIL_PASSWORD [ password of sender and authenticator ]


                string s = ConfigurationManager.AppSettings["EMAIL_USE_AUTHENTICATION"];
                if (!String.IsNullOrEmpty(s))
                {
                    if (s.ToUpper() == "TRUE")
                    {
                        isAuthenticated = true;
                    }
                }

                s = ConfigurationManager.AppSettings["EMAIL_USE_SSL"];
                if (!String.IsNullOrEmpty(s))
                {
                    if (s.ToUpper() == "TRUE")
                    {
                        isUsingSSL = true;
                    }
                }

                s = ConfigurationManager.AppSettings["SMTP_PORT"];
                if (!int.TryParse(s, out smtpPort))
                {
                    smtpPort = 25;
                }

                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                foreach (string item in Email.To)
                {
                    message.To.Add(item);
                }

                message.Subject = Email.Subject;
                message.From    = new System.Net.Mail.MailAddress(Email.From.ToString());
                // message.From = new MailAddress("*****@*****.**", "CloudEnter");
                message.Body = Email.Body;
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(EmailAppSettings.GetStringValue(EmailAppSettings.Key.SmtpHost));

                if (isAuthenticated)
                {
                    smtp.Credentials = new System.Net.NetworkCredential(EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailUserName), EmailAppSettings.GetStringValue(EmailAppSettings.Key.EmailPassword));
                }


                smtp.EnableSsl = isUsingSSL;


                smtp.Send(message);

                return("Success");
            }
            catch (System.Exception ex)
            {
                return(ex.InnerException.ToString());
            }
        }