Ejemplo n.º 1
0
        public ReturnClass BackupToLocal()
        {
            string      message = "";
            ReturnClass outcome = BackupToLocalB();

            return(outcome);
        }
Ejemplo n.º 2
0
        public ReturnClass SendMSMQMessage(EmailItemClass obj, string queuepath, string info)
        {
            ReturnClass  outcome    = new ReturnClass(true);
            MessageQueue MyMessageQ = null;
            Message      MyMessage  = null;

            try {
                MyMessageQ = new MessageQueue(queuepath);
            } catch (Exception ex) {
                outcome.Success     = false;
                outcome.Techmessage = "Error connecting to message queue (" + queuepath + ") Error:[" + ex.Message + "]";
            }
            if (outcome.Success == true)
            {
                try {
                    MyMessage = new Message();
                    MyMessage.UseDeadLetterQueue = true;
                    MyMessage.Formatter          = new System.Messaging.BinaryMessageFormatter();
                    MyMessage.Body = obj;
                } catch (Exception ex) {
                    outcome.Success     = false;
                    outcome.Techmessage = "Error creating Message for queue. Error:[" + ex.Message + "]";
                }
            }
            if (outcome.Success == true)
            {
                try {
                    MyMessageQ.Send(MyMessage, "Message from MSMQ Email Service. Info:[" + info + "]");
                } catch (Exception ex) {
                    outcome.Success     = false;
                    outcome.Techmessage = "Error sending message. Error:[" + ex.Message + "]";
                }
            }
            return(outcome);
        }
Ejemplo n.º 3
0
        public ReturnClass RestoreFromRemoteServer()
        {
            string      message = "";
            ReturnClass outcome = BackupRemote();

            if (outcome.Success == true)
            {
                outcome = CopyRemoteToLocal();
                if (outcome.Success == true)
                {
                    outcome = RestoreLocalServerFromB();
                    if (outcome.Success == false)
                    {
                        message         = outcome.Message + " " + outcome.Techmessage;
                        outcome.Message = "RestoreFromRemoteServer Failed. Backup Succeeded, File move succeeded, local restore failed (part 3) >> " + message;
                    }
                }
                else
                {
                    message         = outcome.Message + " " + outcome.Techmessage;
                    outcome.Message = "RestoreFromRemoteServer Failed. Backup Succeeded, File move failed (part 2) >> " + message;
                }
            }
            else
            {
                message         = outcome.Message + " " + outcome.Techmessage;
                outcome.Message = "RestoreFromRemoteServer Failed. Backup Failed (part 1) >> " + message;
            }

            return(outcome);
        }
Ejemplo n.º 4
0
        private ReturnClass BackupRemote()
        {
            ReturnClass   outcome = new ReturnClass(true);
            SqlConnection conn    = null;
            SqlCommand    command = null;
            string        Sql     = "";
            int           results = 0;

            try{
                Sql     = "Backup Database " + config.DatabaseName + " to disk='" + config.BACKUPREMOTEA + "' WITH INIT";
                conn    = new SqlConnection(config.RemoteConnectionString);
                command = new SqlCommand(Sql, conn);
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                try {
                    results = command.ExecuteNonQuery();
                } catch (Exception ex) {
                    outcome.Success     = false;
                    outcome.Message     = "Backup remote database failed: database:" + config.DatabaseName;
                    outcome.Techmessage = "Backup remote database failed: database:" + config.DatabaseName + " Error:[" + ex.Message + "]";
                }
            } catch (Exception ex) {
                outcome.Success     = false;
                outcome.Message     = "Backup remote database failed: database:" + config.DatabaseName + " Error:[" + ex.Message + "]";
                outcome.Techmessage = "Backup remote database failed: database:" + config.DatabaseName + " Error:[" + ex.Message + "]";
            }
            return(outcome);
        }
Ejemplo n.º 5
0
        public ReturnClass ExecSql(string strQuery)
        {
            ReturnClass outcome = new ReturnClass(true);
            SqlCommand  cmd     = null;
            int         results = 0;

            try{
                cmd = new SqlCommand(strQuery, conn);
                if (commandtimeout > 0)
                {
                    cmd.CommandTimeout = commandtimeout;
                }
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                results = cmd.ExecuteNonQuery();
            }catch (Exception ex) {
                outcome.Success     = false;
                outcome.Message     = "An update query Failed. Please see logs for exact error";
                outcome.Techmessage = "ExecSql error. Query is[" + strQuery + "] Error:[" + ex.Message + "]";
                results             = -1;
            }finally{
                if (cmd != null)
                {
                    cmd.Dispose();
                }
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
            outcome.Intvar = results;
            return(outcome);
        }
Ejemplo n.º 6
0
        public ReturnClass BackupToRemoteAndRestore()
        {
            string      message = "";
            ReturnClass outcome = BackupToLocalB();

            if (outcome.Success == true)
            {
                outcome = CopyLocalToRemote();
                if (outcome.Success == true)
                {
                    outcome = RestoreRemoteServer();
                    if (outcome.Success == false)
                    {
                        message         = outcome.Message + " " + outcome.Techmessage;
                        outcome.Message = "BackupToRemote Failed. Backup succeeded - File copy succeeded  - Restore Failed (part 3) >> " + message;
                    }
                }
                else
                {
                    message         = outcome.Message + " " + outcome.Techmessage;
                    outcome.Message = "BackupToRemote Failed. Backup succeeded - File copy failed (part 2) >> " + message;
                }
            }
            else
            {
                message         = outcome.Message + " " + outcome.Techmessage;
                outcome.Message = "BackupToRemote Failed. Backup section failed (part 1) >> " + message;
            }
            return(outcome);
        }
Ejemplo n.º 7
0
        private ReturnClass RestoreLocalServerFromB()
        {
            ReturnClass   outcome = new ReturnClass(true);
            SqlConnection conn    = null;
            SqlCommand    command = null;
            string        Sql     = "";
            int           results = 0;

            Sql  = "USE MASTER ";
            Sql += "RESTORE DATABASE " + config.DatabaseName + " " +
                   " FROM DISK = '" + config.BACKUPLOCAL2 + "' " +
                   " WITH REPLACE," +
                   " MOVE '" + config.DatabaseName + "' TO '" + config.LOCALMDF + "', " +
                   " MOVE '" + config.DatabaseName + "_log' TO '" + config.LOCALLDF + "'";

            conn    = new SqlConnection(config.RemoteConnectionString);
            command = new SqlCommand(Sql, conn);
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            try {
                results = command.ExecuteNonQuery();
            } catch (Exception ex) {
                outcome.Success     = false;
                outcome.Message     = "Restore local database failed:" + config.DatabaseName + " Error:[" + ex.Message + "]";
                outcome.Techmessage = "Restore local database failed:" + config.DatabaseName + " Error:[" + ex.Message + "]";
            }
            return(outcome);
        }
Ejemplo n.º 8
0
        public ReturnClass ActionById(int actionid)
        {
            ReturnClass outcome = new ReturnClass(true);

            switch (actionid)
            {
            case 1:
                outcome = BackupToLocalA();
                break;

            case 2:
                outcome = RestoreLocalServerFromA();
                break;

            case 3:
                outcome = BackupToLocalB();
                break;

            case 4:
                outcome = BackupToRemote();
                break;

            case 5:
                outcome = BackupToRemoteAndRestore();
                break;

            case 6:
                outcome = RestoreFromRemoteServer();
                break;
            }
            return(outcome);
        }
Ejemplo n.º 9
0
        public ReturnClass GetStringScalarParams(string procname, SP_Parameters p)
        {
            ReturnClass outcome = new ReturnClass(true);
            SqlCommand  cmd     = null;
            // DO NOT SPECIFY OUTPUT PARAMS WITHIN p.
            // All procs must have output param named @out
            string outy = "";

            try {
                cmd = new SqlCommand(procname, conn);
                if (commandtimeout > 0)
                {
                    cmd.CommandTimeout = commandtimeout;
                }
                cmd.CommandType = CommandType.StoredProcedure;
                if (p != null)
                {
                    foreach (SqlParameter objparam1 in p)
                    {
                        cmd.Parameters.Add(objparam1);
                    }
                }

                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                cmd.ExecuteNonQuery();
                outy = cmd.Parameters[cmd.Parameters.Count - 1].Value.ToString();
            } catch (Exception ex) {
                outcome.Success     = false;
                outcome.Message     = "An GetStringScalarParams query Failed. Please see logs for exact error";
                outcome.Techmessage = "GetStringScalarParams error. Procedure is[" + procname + "] Error:[" + ex.ToString() + "]";
            } finally {
                if (cmd != null)
                {
                    cmd.Dispose();
                }
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
            if (outcome.Success)
            {
                outcome.Message = outy;
            }
            return(outcome);
        }
Ejemplo n.º 10
0
        private ReturnClass CopyRemoteToLocal()
        {
            FileInfo    Localfile = null;
            ReturnClass outcome   = new ReturnClass(true);

            try {
                Localfile = new FileInfo(config.BACKUPREMOTEB);
                Localfile.CopyTo(config.BACKUPLOCAL2, true);
            } catch (Exception ex) {
                outcome.Success     = false;
                outcome.Message     = "Copy remote backup to local backup failed! Database:" + config.DatabaseName + " Error:[" + ex.Message + "]";
                outcome.Techmessage = "Copy remote backup to local backup failed! Database:" + config.DatabaseName + " Error:[" + ex.Message + "]";
            }
            return(outcome);
        }
Ejemplo n.º 11
0
        public ReturnClass ExecProcIntResultParams(string procname, SP_Parameters p)
        {
            ReturnClass outcome = new ReturnClass(true);
            SqlCommand  cmd     = null;
            int         outy    = 0;
            int         i       = 0;

            try{
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                cmd = new SqlCommand();
                if (commandtimeout > 0)
                {
                    cmd.CommandTimeout = commandtimeout;
                }
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = procname;
                cmd.Connection  = conn;
                if (p != null)
                {
                    foreach (SqlParameter objparam1 in p)
                    {
                        cmd.Parameters.Add(objparam1);
                    }
                }
                i    = cmd.ExecuteNonQuery();
                outy = (int)cmd.Parameters[cmd.Parameters.Count - 1].Value;
            } catch (Exception ex) {
                outcome.Success     = false;
                outcome.Message     = "An ExecProcIntResultParams query Failed. Please see webmaster for exact error";
                outcome.Techmessage = "ExecProcIntResultParams error. Procedure is[" + procname + "] Error:[" + ex.ToString() + "]";
            } finally {
                if (cmd != null)
                {
                    cmd.Dispose();
                }
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
            outcome.Intvar = outy;
            return(outcome);
        }
Ejemplo n.º 12
0
        public ReturnClass ExecSqlParams(string q, SP_Parameters p)
        {
            ReturnClass outcome = new ReturnClass(true);
            SqlCommand  cmd     = null;
            int         results = 0;

            try {
                cmd = new SqlCommand();
                if (commandtimeout > 0)
                {
                    cmd.CommandTimeout = commandtimeout;
                }
                cmd.Connection  = conn;
                cmd.CommandText = q;
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                if (p != null)
                {
                    foreach (SqlParameter objparam1 in p)
                    {
                        cmd.Parameters.Add(objparam1);
                    }
                }
                results = cmd.ExecuteNonQuery();
            } catch (Exception ex) {
                outcome.Success     = false;
                outcome.Message     = "An update query Failed. Please see logs for exact error";
                outcome.Techmessage = "ExecSqlParams error. Query is[" + q + "] Error:[" + ex.ToString() + "]";
                results             = -1;
            } finally {
                if (cmd != null)
                {
                    cmd.Dispose();
                }
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
            outcome.Intvar = results;
            return(outcome);
        }
Ejemplo n.º 13
0
        public ReturnClass GetLongScalar(string queryString)
        {
            ReturnClass    outcome     = new ReturnClass(true);
            DataTable      returns     = null;
            SqlDataAdapter da          = null;
            long           returnvalue = 0;

            try {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                returns = new DataTable();
                da      = new SqlDataAdapter(queryString, conn);
                da.Fill(returns);
                da.Dispose();
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
                if (returns != null)
                {
                    for (int i = 0; i < returns.Rows.Count; i++)
                    {
                        returnvalue = Convert.ToInt64(returns.Rows[i][0]);
                    }
                }
            } catch (Exception ex) {
                outcome.Success     = false;
                outcome.Message     = "An query failed. Please see logs for exact error";
                outcome.Techmessage = "GetLongScalar error. Query is[" + queryString + "] Error:[" + ex.ToString() + "]";
            } finally {
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
            if (outcome.Success)
            {
                outcome.Longvar = returnvalue;
            }
            return(outcome);
        }
Ejemplo n.º 14
0
        public ReturnClass ExecProcVoid(string procname)
        {
            ReturnClass outcome = new ReturnClass(true);
            SqlCommand  cmd     = null;
            int         i       = 0;

            try {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                cmd = new SqlCommand();
                if (commandtimeout > 0)
                {
                    cmd.CommandTimeout = commandtimeout;
                }
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = procname;
                cmd.Connection  = conn;
                i = cmd.ExecuteNonQuery();
            } catch (Exception ex) {
                outcome.Success     = false;
                outcome.Message     = "An ExecProcVoid query Failed. Please see webmaster for exact error";
                outcome.Techmessage = "ExecProcVoid error. Procedure is[" + procname + "] Error:[" + ex.ToString() + "]";
            } finally {
                if (cmd != null)
                {
                    cmd.Dispose();
                }
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
            return(outcome);
        }
Ejemplo n.º 15
0
        public ReturnClass Send(string toname, string toemail, string fromname, string fromemail, string subject, string body)
        {
            SimpleEmailVO VO      = new SimpleEmailVO();
            ReturnClass   outcome = new ReturnClass(true);

            if (StringFuncs.IsValidEmail(toemail) == true && StringFuncs.IsValidEmail(fromemail))
            {
                VO.ToName    = toname;
                VO.ToEmail   = toemail;
                VO.FromName  = fromname;
                VO.FromEmail = fromemail;
                VO.Subject   = subject;
                VO.TextBody  = body;
                VO.HtmlBody  = body;
                outcome      = Send(VO);
            }
            else
            {
                outcome.Success = false;
                outcome.Message = "One or both of the email addresses are invalid.";
            }

            return(outcome);
        }
Ejemplo n.º 16
0
        public ReturnClass SendMessages(SimpleEmailVOs VOs)
        {
            MailAddress toaddress   = null;
            MailAddress fromaddress = null;
            MailMessage message     = null;

            log = new LoggingClass(logfolder);
            ReturnClass outcome  = new ReturnClass(true);
            ReturnClass mailcome = new ReturnClass(true);

            if (loaded == true)
            {
                try {
                    client = new SmtpClient();
                } catch (Exception ex) {
                    outcome.Success = false;
                    outcome.Message = "There was a problem creating the email component [" + ex.Message + "]";
                }

                if (UseSSL)
                {
                    client.EnableSsl = true;
                }

                if (outcome.Success == true)
                {
                    List <SimpleEmailVO> Emails = VOs.Emails;
                    for (int i = 0; i < Emails.Count; i++)
                    {
                        if (StringFuncs.IsValidEmail(Emails[i].ToEmail) == true && StringFuncs.IsValidEmail(Emails[i].FromEmail))
                        {
                            toaddress          = new MailAddress(Emails[i].ToEmail, Emails[i].ToName);
                            fromaddress        = new MailAddress(Emails[i].FromEmail, Emails[i].FromName);
                            message            = new MailMessage(fromaddress, toaddress);
                            message.Subject    = Emails[i].Subject;
                            message.Body       = Emails[i].HtmlBody;
                            message.IsBodyHtml = Emails[i].IsBodyHtml;
                            try {
                                client.Send(message);
                            } catch (SmtpException ex) {
                                log.Log("EmailClass - Error sending email to " + Emails[i].ToName + " :" + ex.StatusCode + " [" + ex.Message + "][" + ex.InnerException + "]", "MHPNET2EmailLib.EmailClass");
                                mailcome.Success = false;
                                mailcome.AddMessage("EmailClass - Email error " + ex.StatusCode + " [" + ex.Message + "][" + ex.InnerException + "]");
                            } catch (Exception ex) {
                                log.Log("EmailClass - Error sending email to " + Emails[i].ToName + " :" + ex.Message + "", "MHPNET2EmailLib.EmailClass");
                                mailcome.Success = false;
                                mailcome.AddMessage("EmailClass - Email error  [" + ex.Message + "][" + ex.InnerException + "]");
                            }
                        }
                        else
                        {
                            mailcome.Success = false;
                            mailcome.Message = "One or both of the email addresses are invalid.";
                        }
                    }
                }

                if (mailcome.Success == false)
                {
                    outcome.Success = false;
                    outcome.Message = mailcome.Message;
                }
            }
            else
            {
                outcome.Success = false;
                outcome.Message = "The mail component can not be created - most probably the mail configuration is incorrect";
            }
            return(outcome);
        }
Ejemplo n.º 17
0
        public ReturnClass SimpleRestore()
        {
            ReturnClass outcome = RestoreLocalServerFromA();

            return(outcome);
        }
Ejemplo n.º 18
0
        public ReturnClass Send(SimpleEmailVO VO)
        {
            log = new LoggingClass(logfolder);
            ReturnClass outcome = new ReturnClass(true);

            if (StringFuncs.IsValidEmail(VO.ToEmail) == true && StringFuncs.IsValidEmail(VO.FromEmail))
            {
                if (loaded == true)
                {
                    MailAddress toaddress   = new MailAddress(VO.ToEmail, VO.ToName);
                    MailAddress fromaddress = new MailAddress(VO.FromEmail, VO.FromName);
                    MailMessage message     = new MailMessage(fromaddress, toaddress);
                    message.Subject = VO.Subject;
                    if (VO.IsBodyHtml == true)
                    {
                        message.Body = VO.HtmlBody;
                    }
                    else
                    {
                        message.Body = VO.TextBody;
                    }
                    message.IsBodyHtml = VO.IsBodyHtml;
                    message.Priority   = MailPriority.Normal;
                    message.Headers.Add("Return-Path", VO.FromEmail);
                    try {
                        client = new SmtpClient();
                        if (timeout != 100000)
                        {
                            client.Timeout = timeout;
                        }
                        //client.DeliveryMethod = SmtpDeliveryMethod.Network;
                        //client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                        //client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    } catch (Exception ex) {
                        outcome.Success = false;
                        outcome.Message = "There was a problem creating the email component [" + ex.Message + "]";
                    }

                    if (outcome.Success == true)
                    {
                        try {
                            client.Send(message);
                        } catch (SmtpException ex) {
                            log.Log("EmailClass - Error sending email to " + VO.ToName + " :" + ex.StatusCode + " [" + ex.Message + "][" + ex.InnerException + "]", "MHPNET2EmailLib.EmailClass");
                            outcome.Success = false;
                            outcome.Message = "EmailClass - Email error " + ex.StatusCode + " [" + ex.Message + "]";
                        } catch (Exception ex) {
                            log.Log("EmailClass - Error sending email to " + VO.ToName + " :" + ex.Message + "[" + ex.InnerException + "]", "MHPNET2EmailLib.EmailClass");
                            outcome.Success = false;
                            outcome.Message = "EmailClass - Email error  [" + ex.Message + "]";
                        }
                    }
                }
                else
                {
                    outcome.Success = false;
                    outcome.Message = "The mail component can not be created - most probably the mail configuration is incorrect";
                }
            }
            else
            {
                outcome.Success = false;
                outcome.Message = "One or both of the email addresses are invalid.";
            }
            return(outcome);
        }
Ejemplo n.º 19
0
        public ReturnClass SimpleBackup()
        {
            ReturnClass outcome = BackupToLocalA();

            return(outcome);
        }
Ejemplo n.º 20
0
        public ReturnClass UploadImageField(string filepath, string imagefieldparametername, string Sql)
        {
            ReturnClass   outcome   = new ReturnClass(true);
            SP_Parameters p         = new SP_Parameters();
            SqlCommand    cmd       = null;
            Stream        imgStream = null;
            FileInfo      file      = null;

            byte[] imgBinaryData = null;
            int    RowsAffected  = 0;
            int    filesize      = 0;
            int    n             = 0;

            if (!imagefieldparametername.StartsWith("@"))
            {
                imagefieldparametername = "@" + imagefieldparametername;
            }
            if (!File.Exists(filepath))
            {
                outcome.SetFailureMessage("The file does not exist or is not accessible.");
            }

            if (outcome.Success)
            {
                try {
                    file     = new FileInfo(filepath);
                    filesize = Convert.ToInt32(file.Length);
                } catch (Exception ex) {
                    outcome.Success = false;
                    outcome.Message = ex.Message;
                }
            }

            if (outcome.Success)
            {
                try {
                    imgStream     = File.OpenRead(filepath);
                    imgBinaryData = new byte[filesize];
                    n             = imgStream.Read(imgBinaryData, 0, filesize);
                } catch (Exception ex) {
                    outcome.Success = false;
                    outcome.Message = ex.Message;
                }
            }

            if (outcome.Success)
            {
                try {
                    cmd = new SqlCommand(Sql, conn);
                    if (commandtimeout > 0)
                    {
                        cmd.CommandTimeout = commandtimeout;
                    }
                    p.Add(imagefieldparametername, SqlDbType.Image, filesize, ParameterDirection.Input, imgBinaryData);
                    foreach (SqlParameter objparam1 in p)
                    {
                        cmd.Parameters.Add(objparam1);
                    }
                } catch (Exception ex) {
                    outcome.Success = false;
                    outcome.Message = ex.Message;
                }
            }

            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            if (outcome.Success)
            {
                try {
                    RowsAffected = cmd.ExecuteNonQuery();
                } catch (Exception ex) {
                    outcome.Success = false;
                    outcome.Message = ex.Message;
                }
            }
            try {
                imgStream.Close();
            } catch (Exception ex) {
            }
            return(outcome);
        }
Ejemplo n.º 21
0
        public ReturnClass Send(SimpleEmailVO VO, string deliveryemail)
        {
            LoggingClass  log        = new LoggingClass(logfolder);
            ReturnClass   outcome    = new ReturnClass(true);
            AlternateView av1        = null;
            AlternateView av2        = null;
            SmtpClient    mailSender = new SmtpClient();

            if (VO.FromName.Length == 0)
            {
                VO.FromName = VO.FromEmail;
            }
            if (VO.ToName.Length == 0)
            {
                VO.ToName = VO.ToEmail;
            }

            if (StringFuncs.IsValidEmail(VO.FromEmail) && StringFuncs.IsValidEmail(VO.ToEmail))
            {
                MailMessage mailMessage = new MailMessage(new MailAddress(VO.FromEmail, VO.FromName), new MailAddress(VO.ToEmail, VO.ToName));

                if (StringFuncs.IsValidEmail(deliveryemail))
                {
                    mailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess | DeliveryNotificationOptions.OnFailure | DeliveryNotificationOptions.Delay;
                    mailMessage.Headers.Add("Disposition-Notification-To", deliveryemail);

                    //mailMessage.Headers.Add("Errors-To", Config.EmailerDeliveryEmail);
                    //mailMessage.Headers.Add("Delivered-To", Config.EmailerDeliveryEmail);
                    //mailMessage.Headers.Add("Return-Receipt-Requested", Config.EmailerDeliveryEmail);
                    //mailMessage.Headers.Add("Return-Receipt-To", Config.EmailerDeliveryEmail);
                    //mailMessage.Headers.Add("Read-Receipt-Requested", Config.EmailerDeliveryEmail);
                    //mailMessage.Headers.Add("Read-Receipt-To", Config.EmailerDeliveryEmail);
                    //mailMessage.Headers.Add("X-Confirm-reading-to", Config.EmailerDeliveryEmail);
                }

                try {
                    if (VO.HtmlBody.Length > 0)
                    {
                        if (VO.TextBody.Length > 0)
                        {
                            av2 = AlternateView.CreateAlternateViewFromString(VO.TextBody, null, MediaTypeNames.Text.Plain);
                            mailMessage.AlternateViews.Add(av2);
                            av1 = AlternateView.CreateAlternateViewFromString(VO.HtmlBody, Encoding.UTF8, MediaTypeNames.Text.Html);
                            mailMessage.AlternateViews.Add(av1);
                        }
                        else
                        {
                            av1 = AlternateView.CreateAlternateViewFromString(VO.HtmlBody, Encoding.UTF8, MediaTypeNames.Text.Html);
                            mailMessage.AlternateViews.Add(av1);
                        }
                    }
                    else
                    {
                        av2 = AlternateView.CreateAlternateViewFromString(VO.TextBody, null, MediaTypeNames.Text.Plain);
                        mailMessage.AlternateViews.Add(av2);
                    }
                } catch (Exception ex) {
                    outcome.SetFailureMessage("Error setting email body:" + ex.ToString());
                }

                if (outcome.Success)
                {
                    try {
                        mailMessage.Subject = VO.Subject;
                        if (VO.HtmlBody.Length > 0)
                        {
                            mailMessage.IsBodyHtml = true;
                        }
                        else
                        {
                            mailMessage.IsBodyHtml = false;
                        }
                        mailMessage.Priority = MailPriority.Normal;

                        if (StringFuncs.IsValidEmail(VO.ReplyToEmail))
                        {
                            mailMessage.Headers.Add("Return-Path", VO.ReplyToEmail);
                            mailMessage.ReplyTo = new MailAddress(VO.ReplyToEmail, VO.ReplyToEmail);
                        }
                        else
                        {
                            mailMessage.Headers.Add("Return-Path", VO.FromEmail);
                            mailMessage.ReplyTo = new MailAddress(VO.FromEmail, VO.FromName);
                        }

                        mailSender.EnableSsl = UseSSL;
                    } catch (Exception ex) {
                        outcome.SetFailureMessage("Error setting message settings:" + ex.ToString());
                    }

                    if (outcome.Success)
                    {
                        try {
                            mailSender.Send(mailMessage);
                        } catch (SmtpException ex) {
                            log.Log("EmailClass - Error sending email to " + VO.ToName + " :" + ex.StatusCode + " [" + ex.Message + "][" + ex.InnerException + "]", "MHPNET2EmailLib.EmailClass");
                            outcome.SetFailureMessage("EmailClass - Email error " + ex.StatusCode + " [" + ex.Message + "]");
                        } catch (Exception ex) {
                            log.Log("EmailClass - Error sending email to " + VO.ToName + " :" + ex.Message + "[" + ex.InnerException + "]", "MHPNET2EmailLib.EmailClass");
                            outcome.SetFailureMessage("EmailClass - Email error  [" + ex.Message + "]");
                        }
                    }
                }
            }
            else
            {
                outcome.SetFailureMessage("Either the target (" + VO.ToEmail + ") or sender email (" + VO.FromEmail + ")is invalid");
            }

            return(outcome);
        }
Ejemplo n.º 22
0
        public ReturnClass GetDoubleScalarParams(string Sql, SP_Parameters p)
        {
            ReturnClass    outcome     = new ReturnClass(true);
            double         returnvalue = -1;
            DataTable      dt          = new DataTable();
            SqlCommand     cmd         = null;
            SqlDataAdapter da          = null;

            try {
                cmd = new SqlCommand();
                if (commandtimeout > 0)
                {
                    cmd.CommandTimeout = commandtimeout;
                }
                cmd.Connection  = conn;
                cmd.CommandText = Sql;
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                if (p != null)
                {
                    foreach (SqlParameter objparam1 in p)
                    {
                        cmd.Parameters.Add(objparam1);
                    }
                }
                da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                da.Dispose();
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
                if (dt != null)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        returnvalue = Convert.ToDouble(dt.Rows[i][0]);
                    }
                }
            } catch (Exception ex) {
                outcome.Success     = false;
                outcome.Message     = "A query Failed. Please see logs for exact error";
                outcome.Techmessage = "GetIntScalarParams error. Query is[" + Sql + "] Error:[" + ex.ToString() + "]";
            } finally {
                if (cmd != null)
                {
                    cmd.Dispose();
                }
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
            }
            if (outcome.Success)
            {
                outcome.Doublevar = returnvalue;
            }
            return(outcome);
        }
Ejemplo n.º 23
0
        public ReturnClass Send(SimpleEmailVO VO)
        {
            MailAddress toaddress    = null;
            MailAddress fromaddress  = null;
            MailAddress replyaddress = null;
            MailMessage message      = null;

            log = new LoggingClass(logfolder);
            ReturnClass outcome = new ReturnClass(true);

            if (StringFuncs.IsValidEmail(VO.ToEmail) && StringFuncs.IsValidEmail(VO.FromEmail))
            {
                if (loaded == true)
                {
                    try {
                        toaddress   = new MailAddress(VO.ToEmail, VO.ToName);
                        fromaddress = new MailAddress(VO.FromEmail, VO.FromName);
                        message     = new MailMessage(fromaddress, toaddress);
                    } catch (Exception ex) {
                        outcome.Success = false;
                        outcome.Message = "There was a problem creating the addresses or message [" + ex.Message + "]";
                    }
                    if (outcome.Success)
                    {
                        try {
                            message.Subject = VO.Subject;

                            if (VO.IsBodyHtml == true)
                            {
                                message.Body = VO.HtmlBody;
                            }
                            else
                            {
                                message.Body = VO.TextBody;
                            }
                            message.IsBodyHtml = VO.IsBodyHtml;
                            message.Priority   = MailPriority.Normal;
                            message.Headers.Add("Return-Path", VO.FromEmail);
                        } catch (Exception ex) {
                            outcome.Success = false;
                            outcome.Message = "There was a problem setting the message parts(priority, return-path) [" + ex.Message + "]";
                        }
                    }
                    if (outcome.Success)
                    {
                        if (VO.ReplyToEmail.Length > 0 && StringFuncs.IsValidEmail(VO.ReplyToEmail))
                        {
                            if (VO.ReplyToName.Length > 0)
                            {
                                replyaddress = new MailAddress(VO.ReplyToEmail, VO.ReplyToName);
                            }
                            else
                            {
                                replyaddress = new MailAddress(VO.ReplyToEmail, VO.ReplyToEmail);
                            }
                            message.ReplyTo = replyaddress;
                        }
                    }

                    if (outcome.Success)
                    {
                        try {
                            client = new SmtpClient();
                        } catch (Exception ex) {
                            outcome.Success = false;
                            outcome.Message = "There was a problem creating the email component [" + ex.Message + "]";
                        }
                    }
                    if (outcome.Success)
                    {
                        if (UseSSL)
                        {
                            client.EnableSsl = true;
                        }
                    }
                    if (outcome.Success)
                    {
                        try {
                            client.Send(message);
                        } catch (SmtpException ex) {
                            log.Log("EmailClass - Error sending email to " + VO.ToName + " :" + ex.StatusCode + " [" + ex.Message + "][" + ex.InnerException + "]", "MHPNET2EmailLib.EmailClass");
                            outcome.Success = false;
                            outcome.Message = "EmailClass - Email error " + ex.StatusCode + " [" + ex.Message + "]";
                        } catch (Exception ex) {
                            log.Log("EmailClass - Error sending email to " + VO.ToName + " :" + ex.Message + "[" + ex.InnerException + "]", "MHPNET2EmailLib.EmailClass");
                            outcome.Success = false;
                            outcome.Message = "EmailClass - Email error  [" + ex.Message + "]";
                        }
                    }
                }
                else
                {
                    outcome.Success = false;
                    outcome.Message = "The mail component can not be created - most probably the mail configuration is incorrect";
                }
            }
            else
            {
                outcome.Success = false;
                outcome.Message = "One or both of the email addresses are invalid.";
            }
            return(outcome);
        }