Esempio n. 1
0
        public static MailCommand GetMailCommand(MailCommandDataSet mailCommandDataSet, string command)
        {
            MailCommand result = new MailCommand();

            DataRow[] dr = mailCommandDataSet.Tables[0].Select("Command='" + command + "'");

            if (dr.Length == 0)
            {
                throw new Exception("No command found for " + command);
            }

            if (dr.Length > 1)
            {
                throw new Exception("Too many command found for " + command);
            }


            result.Command        = dr[0]["Command"].ToString();
            result.Connection     = dr[0]["Connection"].ToString();
            result.Description    = dr[0]["Description"].ToString();
            result.SqlCommandText = dr[0]["SqlCommandText"].ToString();
            result.CommandType    = CommandType.MailCommand;

            return(result);
        }
Esempio n. 2
0
        private void EditToolStripButton_Click(object sender, EventArgs e)
        {
            if (MailCommandDataGridView.SelectedRows.Count == 0)
            {
                return;
            }

            DataGridViewRow row = MailCommandDataGridView.SelectedRows[0];
            MailCommand     cmd = new MailCommand();

            cmd.Command        = row.Cells["colCommand"].Value.ToString();
            cmd.Connection     = row.Cells["colConnection"].Value.ToString();
            cmd.Description    = row.Cells["colDescription"].Value.ToString();
            cmd.SqlCommandText = row.Cells["colSqlCommandText"].Value.ToString();
            cmd.CommandType    = CommandType.MailCommand;

            MailCommandForm frm = new MailCommandForm(cmd);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                row.Cells["colCommand"].Value        = cmd.Command;
                row.Cells["colConnection"].Value     = cmd.Connection;
                row.Cells["colDescription"].Value    = cmd.Description;
                row.Cells["colSqlCommandText"].Value = cmd.SqlCommandText;
                //row.Cells["colCommandType"].Value = cmd.CommandType;

                SaveMailCommandList();
            }
        }
Esempio n. 3
0
        private void NewToolStripButton_Click(object sender, EventArgs e)
        {
            MailCommand cmd = new MailCommand();

            cmd.CommandType = CommandType.MailCommand;
            MailCommandForm frm = new MailCommandForm(cmd);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                ds.Tables[0].Rows.Add(cmd.Command, cmd.Connection, cmd.Description, cmd.SqlCommandText);
                SaveMailCommandList();
            }
        }
        //method to send email to outlook
        private static void sendEMailThroughOUTLOOK(MailCommand mailCommand)
        {
            try
            {
                // Create the Outlook application.
                Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
                // Create a new mail item.
                Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                // Set HTMLBody.
                //add the body of the email
                if (mailCommand.Exception != null)
                {
                    oMsg.HTMLBody = "Error !!!" + Environment.NewLine + Environment.NewLine + mailCommand.Exception.Message;
                }
                else if (mailCommand.CommandType == CommandType.Exit | mailCommand.CommandType == CommandType.Hi | mailCommand.CommandType == CommandType.Stop | mailCommand.CommandType == CommandType.Start)
                {
                    oMsg.HTMLBody = mailCommand.Description;
                }
                else
                {
                    oMsg.HTMLBody = ConvertToHtmlFile(mailCommand);
                }

                //Add an attachment.
                //String sDisplayName = "MyAttachment";
                int iPosition = (int)oMsg.Body.Length + 1;
                //int iAttachType = (int)Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue;
                //now attached the file
                //Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName);
                //Subject line
                oMsg.Subject = mailCommand.Command + " Executed (" + DateTime.Now.ToLongTimeString() + ")";
                // Add a recipient.
                Microsoft.Office.Interop.Outlook.Recipients oRecips = (Microsoft.Office.Interop.Outlook.Recipients)oMsg.Recipients;
                // Change the recipient in the next line if necessary.
                Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add(mailCommand.ToAddress);
                oRecip.Resolve();
                // Send.
                oMsg.Send();
                // Clean up.
                oRecip  = null;
                oRecips = null;
                oMsg    = null;
                oApp    = null;

                Logger.Log(mailCommand.Command + " Result Send To " + mailCommand.ToAddress);
            }//end of try block
            catch (Exception ex)
            {
                Logger.Log(ex.Message);
            } //end of catch
        }     //end of Email Method
        }     //end of Email Method

        private static string ConvertToHtmlFile(MailCommand mailCommand)
        {
            string result = "";


            if (mailCommand.Data == null)
            {
                throw new System.ArgumentNullException("Invalid MailCommand.Data");
            }
            else
            {
                //Continue.
            }


            //Get a worker object.
            StringBuilder htmlBuilder = new StringBuilder();


            //Open tags and write the top portion.
            htmlBuilder.Append("<html>");
            htmlBuilder.Append("<head>");
            htmlBuilder.Append("<title>");
            htmlBuilder.Append("Page-");
            htmlBuilder.Append(Guid.NewGuid().ToString());
            htmlBuilder.Append("</title>");
            htmlBuilder.Append("</head>");
            htmlBuilder.Append("<body>");

            foreach (DataTable dt in mailCommand.Data.Tables)
            {
                ConvertDataTableToHtmlTable(dt, htmlBuilder);
                htmlBuilder.Append("</br></br></br>&nbsp  &nbsp  ");
            }

            htmlBuilder.Append("<br>Connection : " + mailCommand.Connection);
            htmlBuilder.Append("<br>Description : " + mailCommand.Description);

            htmlBuilder.Append("</body>");
            htmlBuilder.Append("</html>");


            //Get the string for return.
            result = htmlBuilder.ToString();

            return(result);
        }
Esempio n. 6
0
        private void TestToolStripButton_Click(object sender, EventArgs e)
        {
            if (MailCommandDataGridView.SelectedRows.Count == 0)
            {
                return;
            }

            DataGridViewRow row = MailCommandDataGridView.SelectedRows[0];
            MailCommand     cmd = new MailCommand();

            cmd.Command        = row.Cells["colCommand"].Value.ToString();
            cmd.Connection     = row.Cells["colConnection"].Value.ToString();
            cmd.Description    = row.Cells["colDescription"].Value.ToString();
            cmd.SqlCommandText = row.Cells["colSqlCommandText"].Value.ToString();
            cmd.CommandType    = CommandType.MailCommand;
            cmd.ToAddress      = "*****@*****.**";

            MailCommandExecutor.Execute(cmd);

            MessageBox.Show("Command Excuted and Result Mail Send To [email protected]");
        }
        public static void Execute(MailCommand mailCommand)
        {
            if (mailCommand.CommandType == CommandType.MailCommand)
            {
                try
                {
                    if (mailCommand.GetConnectionProviderName().Contains("Oracle"))
                    {
                        mailCommand.Data = ExecuteOracleDataset(mailCommand.GetConnectionString(), mailCommand.SqlCommandText);
                    }
                    else
                    {
                        mailCommand.Data = ExecuteSqlDataSet(mailCommand.GetConnectionString(), mailCommand.SqlCommandText);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log("ERROR : " + ex.Message);
                    mailCommand.Exception = ex;
                }
            }

            sendEMailThroughOUTLOOK(mailCommand);
        }
        private static void ExecuteMail(Microsoft.Office.Interop.Outlook.MailItem mail)
        {
            string      command = mail.Subject.Replace("MC ", "");
            MailCommand mailCommand;

            Logger.Log("Mail Received From:" + mail.SenderEmailAddress + " Subject:" + mail.Subject);

            if (!IsAllowedMail(mail.SenderEmailAddress))
            {
                Logger.Log(mail.SenderEmailAddress + " Is Not Allowed :-(");
                return;
            }

            if (command == "EXIT")
            {
                Logger.Log("Application Exiting");
                Helper.MainForm.Close();
                return;
            }


            if (command == "STOP")
            {
                Logger.Log("Service Is Stoping");
                Helper.MainForm.StopService();
                mailCommand             = new MailCommand();
                mailCommand.Command     = "STOP";
                mailCommand.CommandType = CommandType.Stop;
                mailCommand.Description = "Mail Command Service Stoped";
                mailCommand.ToAddress   = mail.SenderEmailAddress;
                Execute(mailCommand);
                Logger.Log("Service Is Stoped");
                return;
            }

            if (command == "START")
            {
                Logger.Log("Service Is Starting");
                Helper.MainForm.StartService();
                mailCommand             = new MailCommand();
                mailCommand.Command     = "START";
                mailCommand.CommandType = CommandType.Start;
                mailCommand.Description = "Mail Command Service Started";
                mailCommand.ToAddress   = mail.SenderEmailAddress;
                Execute(mailCommand);
                Logger.Log("Service Is Stoped");
                return;
            }

            if (command == "HI")
            {
                mailCommand             = new MailCommand();
                mailCommand.Command     = "HI";
                mailCommand.CommandType = CommandType.Hi;
                mailCommand.Description = "Hi :-)), Im here for your command.";
                mailCommand.ToAddress   = mail.SenderEmailAddress;
                Execute(mailCommand);
                return;
            }

            if (command == "CL")
            {
                mailCommand             = new MailCommand();
                mailCommand.Command     = "CL";
                mailCommand.CommandType = CommandType.CommandList;
                mailCommand.Data        = Helper.GetCommandList();
                mailCommand.Description = "Command List :-)";
                mailCommand.ToAddress   = mail.SenderEmailAddress;
                Execute(mailCommand);
                return;
            }

            if (!Helper.MainForm.IsServiceReply())
            {
                return;
            }


            mailCommand           = Helper.GetMailCommand(command);
            mailCommand.ToAddress = mail.SenderEmailAddress;

            Execute(mailCommand);
        }
Esempio n. 9
0
 public MailCommandForm(MailCommand cmd)
 {
     InitializeComponent();
     this.cmd = cmd;
 }