Beispiel #1
0
        public bool SendMail(ConfigNode cfg, Exception e = null)
        {
            try
             {
            MailSender ms = new MailSender();

            string sendTo,
                   header,
                   message;

            if (e != null)
            {
               header = "[ERROR] " + cfg["header", "MohidRun Report"].AsString();
               sendTo = "sendto.onerror";
               message = cfg["message", "Mohid Run Report"].AsString() + Environment.NewLine;
               message += "Exception raised: " + Environment.NewLine;
               message += e.Message;
            }
            else
            {
               header = "[SUCCESS] " + cfg["header", "MohidRun Report"].AsString();
               sendTo = "sendto.onsuccess";
               message = cfg["message", "Mohid Run Report"].AsString();
            }

            ms.SetFrom(cfg["from"].AsString(), cfg["display", cfg["from"].AsString()].AsString());
            ms.User = cfg["user", "*****@*****.**"].AsString();
            ms.Password = cfg["pass", "MohidOperationalISTMARETEC2011"].AsString();
            ms.SetMessage(message, header);
            ms.Host = cfg["host", "smtp.gmail.com"].AsString();
            ms.Port = cfg["port", 587].AsInt();
            ms.EnableSSL = cfg["enable.ssl", true].AsBool();

            foreach (ConfigNode n in cfg.ChildNodes.FindAll(delegate(ConfigNode node) { return (node.Name == sendTo || node.Name == "sendto"); }))
            {
               if (!(n["bcc", ""].AsString() == ""))
                  ms.AddBCC(n["bcc"].AsString(), n["display", n["bcc"].AsString()].AsString());
               else if (!(n["cc", ""].AsString() == ""))
                  ms.AddCC(n["cc"].AsString(), n["display", n["cc"].AsString()].AsString());
               else
                  ms.AddTo(n["to"].AsString(), n["display", n["to"].AsString()].AsString());
            }

            ms.SendMail();
            last_exception = null;

            return true;
             }
             catch (Exception ex)
             {
            last_exception = ex;
            return false;
             }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            MailSender ms = new MailSender();

             ms.SetFrom("*****@*****.**", "MohidRun");
             ms.User = "******";
             ms.Password ="******";
             ms.SetMessage("teste", "MohidRun Tests");
             ms.Host = "smtp.gmail.com";
             ms.Port = 587;
             ms.AddTo("*****@*****.**", "Eduardo Jauch");
             ms.EnableSSL = true;
             ms.SendMail();

             Console.ReadKey(false);
        }
Beispiel #3
0
        static int Main(string[] args)
        {
            CmdArgs cmdArgs = null;
             Exception e = null;
             bool sendMail = false;
             bool sendSMS = false;
             bool verbose = true;
             IMohidSim stdScript = null;
             int return_value = 0;

             try
             {
            Setup.StandardSetup();
            cmdArgs = new CmdArgs(args);

            if (cmdArgs.HasOption("v"))
               verbose = true;
            else
               verbose = false;

            if (cmdArgs.HasParameter("m"))
               sendMail = true;

            if (cmdArgs.HasParameter("s"))
               sendSMS = true;

            if (cmdArgs.HasOption("i"))
               stdScript = (IMohidSim)new StandardScript();
             }
             catch (Exception ex)
             {
            if (verbose)
               Console.WriteLine("[{0}] Model Runner: Exception raised during initialization: {0}", DateTime.Now, ex.Message);

            return -1;
             }

             try
             {
            MohidRunEngine mre = new MohidRunEngine();
            mre.Verbose = verbose;
            mre.Run(cmdArgs, stdScript);
             }
             catch (Exception ex)
             {
            e = ex;
            return_value = -1;
             }

             if (sendMail)
             {
            try
            {
               Config cfg = new Config(cmdArgs.Parameter("m"));
               if (!cfg.Load())
               {
                  if (verbose)
                     Console.WriteLine("[{0}] Model Runner: Was not possible to load the mail configuration file '{1}'", DateTime.Now, cmdArgs.Parameter("mailcfg"));
               }
               else
               {
                  MailSender ms = new MailSender();

                  string sendTo,
                         header,
                         message;

                  if (e != null)
                  {
                     header = "[ERROR] " + cfg.Root["header", "MohidRun Report"].AsString();
                     sendTo = "sendto.onerror";
                     message = cfg.Root["message", "Mohid Run Report"].AsString() + Environment.NewLine;
                     message += "An exception happened" + e.Message + Environment.NewLine;

                     while (e != null)
                     {
                        message += "  => " + e.Message + Environment.NewLine;
                        e = e.InnerException;
                     }
                  }
                  else
                  {
                     header = "[SUCCESS] " + cfg.Root["header", "MohidRun Report"].AsString();
                     sendTo = "sendto.onsuccess";
                     message = cfg.Root["message", "Mohid Run Report"].AsString();
                  }

                  ms.SetFrom(cfg.Root["from"].AsString(), cfg.Root["display", cfg.Root["from"].AsString()].AsString());
                  ms.User = cfg.Root["user", "*****@*****.**"].AsString();
                  ms.Password = cfg.Root["pass", "MohidOperationalISTMARETEC2011"].AsString();
                  ms.SetMessage(message, header);
                  ms.Host = cfg.Root["host", "smtp.gmail.com"].AsString();
                  ms.Port = cfg.Root["port", 587].AsInt();
                  ms.EnableSSL = cfg.Root["enable.ssl", true].AsBool();

                  foreach (ConfigNode n in cfg.Root.ChildNodes.FindAll(delegate(ConfigNode node) { return (node.Name == sendTo || node.Name == "sendto"); }))
                  {
                     if (!(n["bcc", ""].AsString() == ""))
                        ms.AddBCC(n["bcc"].AsString(), n["display", n["bcc"].AsString()].AsString());
                     else if (!(n["cc", ""].AsString() == ""))
                        ms.AddCC(n["cc"].AsString(), n["display", n["cc"].AsString()].AsString());
                     else
                        ms.AddTo(n["to"].AsString(), n["display", n["to"].AsString()].AsString());
                  }

                  ms.SendMail();
               }
            }
            catch (Exception ex)
            {
               if (verbose)
               {
                  Console.WriteLine("[{0}] Model Runner: Was not possible to send the mail. An EXCEPTION happened. The message returned was:", DateTime.Now);
                  Console.WriteLine("{0}", ex.Message);
               }

               return_value -= 2;
            }
             }

             if (sendSMS)
             {
             }

             return return_value;
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            OPTamegaScript script = new OPTamegaScript();
             CmdArgs cmdArgs = null;
             Exception e = null;
             bool sendMail = false;
             bool sendSMS = false;
             bool verbose = false;

             try
             {
            Setup.StandartSetup();
            cmdArgs = new CmdArgs(args);

            if (cmdArgs.HasParameter("mailcfg"))
               sendMail = true;

            if (cmdArgs.HasParameter("smscfg"))
               sendSMS = true;

            if (cmdArgs.HasOption("verbose"))
               verbose = true;
             }
             catch (Exception ex)
             {
            Console.WriteLine("Exception raised during initialization: {0}", ex.Message);
            return;
             }

             try
             {
            if (Run(cmdArgs, verbose))
               throw new Exception("Run failed.");
             }
             catch (Exception ex)
             {
            e = ex;
             }

             if (sendMail)
             {
            try
            {
               Config cfg = new Config(cmdArgs.Parameter("mailcfg"));
               if (!cfg.Load())
               {
                  Console.WriteLine("[{0}] Was not possible to load the mail configuration file '{1}'", DateTime.Now, cmdArgs.Parameter("mailcfg"));
               }
               else
               {
                  MailSender ms = new MailSender();

                  string sendTo,
                         header,
                         message;

                  if (e != null)
                  {
                     header = "[ERROR] " + cfg.Root["header", "MohidRun Report"].AsString();
                     sendTo = "sendto.onerror";
                     message = cfg.Root["message", "Mohid Run Report"].AsString() + Environment.NewLine;
                     message += "Exception raised: " + Environment.NewLine;
                     message += e.Message;
                  }
                  else
                  {
                     header = "[SUCCESS] " + cfg.Root["header", "MohidRun Report"].AsString();
                     sendTo = "sendto.onsuccess";
                     message = cfg.Root["message", "Mohid Run Report"].AsString();
                  }

                  ms.SetFrom(cfg.Root["from"].AsString(), cfg.Root["display", cfg.Root["from"].AsString()].AsString());
                  ms.User = cfg.Root["user", "*****@*****.**"].AsString();
                  ms.Password = cfg.Root["pass", "MohidOperationalISTMARETEC2011"].AsString();
                  ms.SetMessage(message, header);
                  ms.Host = cfg.Root["host", "smtp.gmail.com"].AsString();
                  ms.Port = cfg.Root["port", 587].AsInt();
                  ms.EnableSSL = cfg.Root["enable.ssl", true].AsBool();

                  foreach (ConfigNode n in cfg.Root.ChildNodes.FindAll(delegate(ConfigNode node) { return (node.Name == sendTo || node.Name == "sendto"); }))
                  {
                     if (!(n["bcc", ""].AsString() == ""))
                        ms.AddBCC(n["bcc"].AsString(), n["display", n["bcc"].AsString()].AsString());
                     else if (!(n["cc", ""].AsString() == ""))
                        ms.AddCC(n["cc"].AsString(), n["display", n["cc"].AsString()].AsString());
                     else
                        ms.AddTo(n["to"].AsString(), n["display", n["to"].AsString()].AsString());
                  }

                  ms.SendMail();
               }
            }
            catch (Exception ex)
            {
               Console.WriteLine("[{0}] Was not possible to send the mail. An EXCEPTION happened. The message returned was:", DateTime.Now);
               Console.WriteLine("{0}", ex.Message);
            }
             }

             if (sendSMS)
             {
             }
        }