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; } }
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); }
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; }
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) { } }
public void prrRulseMailAlert(string prr_guid) { string mailTitle = ""; string mailBody = ""; string type = ""; try { type = sqlHelper.ExecuteScalar(@"select t1.type from sys_rules_show t left join sys_rules_testrun t1 on t.rules_guid=t1.guid left join mir t2 on t.stdfid=t2.stdfid where t.guid='" + prr_guid + "'").ToString(); } catch (Exception) { } MailSender mail = new MailSender(); List <string> recevicerList = new List <string>(); recevicerList.Add("*****@*****.**"); mail.AddTo(recevicerList.ToArray()); switch (type) { case "BINCOUNTTRIGGER": mailTitle = sqlHelper.ExecuteScalar(@"select t1.action||'_'||t1.type||'_'||t1.product||'_'||t2.lotid||'_'||t2.testcod||'_'||t2.sblotid||'_'||t.eqname||'_'||to_char(t.rules_time,'yyyyMMddHHmmss') from sys_rules_show t left join sys_rules_testrun t1 on t.rules_guid=t1.guid left join mir t2 on t.stdfid=t2.stdfid where t.guid='" + prr_guid + "'").ToString(); DataSet ds_BINCOUNTTRIGGER = sqlHelper.ExecuteDataSet(@"select t.rules_time,t1.action, '['||t1.type||'/'||t1.name||']:', 'LowLimit=null HighLimit='||case t1.counttype when '0' then t1.count when '1' then t1.count||'%' else 'null' end || ' site='||t.sitenum||' value='||t.remark, 'MAX_site=null MAX_value=null MIN_site=null MIN_value=null GAP=null' from sys_rules_show t left join sys_rules_testrun t1 on t.rules_guid=t1.guid left join mir t2 on t.stdfid=t2.stdfid where t.guid='" + prr_guid + "'"); mailBody = ds_BINCOUNTTRIGGER.Tables[0].Rows[0][0].ToString() + "," + ds_BINCOUNTTRIGGER.Tables[0].Rows[0][1].ToString() + "<br/>"; mailBody += ds_BINCOUNTTRIGGER.Tables[0].Rows[0][2].ToString() + "<br/>"; mailBody += ds_BINCOUNTTRIGGER.Tables[0].Rows[0][3].ToString() + "<br/>"; mailBody += ds_BINCOUNTTRIGGER.Tables[0].Rows[0][4].ToString(); mail.Send(mailTitle, mailBody); break; case "SITETOSITEYIELD": mailTitle = sqlHelper.ExecuteScalar(@"select t1.action||'_'||t1.type||'_'||t1.product||'_'||t2.lotid||'_'||t2.testcod||'_'||t2.sblotid||'_'||t.eqname||'_'||to_char(t.rules_time,'yyyyMMddHHmmss') from sys_rules_show t left join sys_rules_testrun t1 on t.rules_guid=t1.guid left join mir t2 on t.stdfid=t2.stdfid where t.guid='" + prr_guid + "'").ToString(); DataSet ds_SITETOSITEYIELD = sqlHelper.ExecuteDataSet(@"select t.rules_time,t1.action,t.remark, '['||t1.type||'/'||t1.name||']:', 'LowLimit=null HighLimit='||case t1.counttype when '0' then t1.count when '1' then t1.count||'%' else 'null' end || ' site='||t.sitenum||' value='|| (to_number(NVL(substr(t.remark,instr(t.remark,'=',1,1)+1,instr(t.remark,',',1,1)-instr(t.remark,'=',1,1)-1),0))- to_number(NVL(substr(t.remark,instr(t.remark,'=',1,2)+1,instr(t.remark,',',1,2)-instr(t.remark,'=',1,2)-1),0)))||'%', 'MAX_site='||substr(t.remark,instr(t.remark,'=',1,3)+1,instr(t.remark,',',1,3)-instr(t.remark,'=',1,3)-1)|| ' MAX_value='||substr(t.remark,instr(t.remark,'=',1,1)+1,instr(t.remark,',',1,1)-instr(t.remark,'=',1,1)-1)||'%'|| ' MIN_site='||substr(t.remark,instr(t.remark,'=',1,4)+1,instr(t.remark,',',1,4)-instr(t.remark,'=',1,4)-1)|| ' MIN_value='||substr(t.remark,instr(t.remark,'=',1,2)+1,instr(t.remark,',',1,2)-instr(t.remark,'=',1,2)-1)||'%'|| ' GAP='||(to_number(NVL(substr(t.remark,instr(t.remark,'=',1,1)+1,instr(t.remark,',',1,1)-instr(t.remark,'=',1,1)-1),0))- to_number(NVL(substr(t.remark,instr(t.remark,'=',1,2)+1,instr(t.remark,',',1,2)-instr(t.remark,'=',1,2)-1),0)))||'%' from sys_rules_show t left join sys_rules_testrun t1 on t.rules_guid=t1.guid left join mir t2 on t.stdfid=t2.stdfid where t.guid='" + prr_guid + "'"); mailBody = ds_SITETOSITEYIELD.Tables[0].Rows[0][0].ToString() + "," + ds_SITETOSITEYIELD.Tables[0].Rows[0][1].ToString() + "<br/>"; mailBody += ds_SITETOSITEYIELD.Tables[0].Rows[0][2].ToString() + "<br/>"; mailBody += ds_SITETOSITEYIELD.Tables[0].Rows[0][3].ToString() + "<br/>"; mailBody += ds_SITETOSITEYIELD.Tables[0].Rows[0][4].ToString(); mail.Send(mailTitle, mailBody); break; case "CONSECUTIVEBINTRIGGER": mailTitle = sqlHelper.ExecuteScalar(@"select t1.action||'_'||t1.type||'_'||t1.product||'_'||t2.lotid||'_'||t2.testcod||'_'||t2.sblotid||'_'||t.eqname||'_'||to_char(t.rules_time,'yyyyMMddHHmmss') from sys_rules_show t left join sys_rules_testrun t1 on t.rules_guid=t1.guid left join mir t2 on t.stdfid=t2.stdfid where t.guid='" + prr_guid + "'").ToString(); DataSet ds_CONSECUTIVEBINTRIGGER = sqlHelper.ExecuteDataSet(@"select t.rules_time,t1.action, '['||t1.type||'/'||t1.name||']:', 'LowLimit=null HighLimit='||case t1.counttype when '0' then t1.count when '1' then t1.count||'%' else 'null' end || ' site='||t.sitenum||' value='||t.remark, 'MAX_site=null MAX_value=null MIN_site=null MIN_value=null GAP=null' from sys_rules_show t left join sys_rules_testrun t1 on t.rules_guid=t1.guid left join mir t2 on t.stdfid=t2.stdfid where t.guid='" + prr_guid + "'"); mailBody = ds_CONSECUTIVEBINTRIGGER.Tables[0].Rows[0][0].ToString() + "," + ds_CONSECUTIVEBINTRIGGER.Tables[0].Rows[0][1].ToString() + "<br/>"; mailBody += ds_CONSECUTIVEBINTRIGGER.Tables[0].Rows[0][2].ToString() + "<br/>"; mailBody += ds_CONSECUTIVEBINTRIGGER.Tables[0].Rows[0][3].ToString() + "<br/>"; mailBody += ds_CONSECUTIVEBINTRIGGER.Tables[0].Rows[0][4].ToString(); mail.Send(mailTitle, mailBody); break; case "PARAMETRICTESTSTATISTICTRIGGER": mailTitle = sqlHelper.ExecuteScalar(@"select t1.action||'_'||t1.type||'_'||t1.product||'_'||t2.lotid||'_'||t2.testcod||'_'||t2.sblotid||'_'||t.eqname||'_'||to_char(t.rules_time,'yyyyMMddHHmmss') from sys_rules_show_ptr t left join sys_rules_testrun t1 on t.rules_guid=t1.guid left join mir t2 on t.stdfid=t2.stdfid where t.guid='" + prr_guid + "'").ToString(); DataSet ds_PARAMETRICTESTSTATISTICTRIGGER = sqlHelper.ExecuteDataSet(@"select t.rules_time,t1.action, '['||t1.type||'/'||t1.name||']:', 'LowLimit='||case t1.minstatus when '0' then t1.minvalue when '1' then t1.minvalue||'%' else 'null' end || ' HighLimit='||case t1.maxstatus when '0' then t1.maxvalue when '1' then t1.maxvalue||'%' else 'null' end || ' site='||t.sitenum||' value='||t.remark, 'MAX_site=null MAX_value=null MIN_site=null MIN_value=null GAP=null' from sys_rules_show_ptr t left join sys_rules_testrun t1 on t.rules_guid=t1.guid left join mir t2 on t.stdfid=t2.stdfid where t.guid='" + prr_guid + "'"); mailBody = ds_PARAMETRICTESTSTATISTICTRIGGER.Tables[0].Rows[0][0].ToString() + "," + ds_PARAMETRICTESTSTATISTICTRIGGER.Tables[0].Rows[0][1].ToString() + "<br/>"; mailBody += ds_PARAMETRICTESTSTATISTICTRIGGER.Tables[0].Rows[0][2].ToString() + "<br/>"; mailBody += ds_PARAMETRICTESTSTATISTICTRIGGER.Tables[0].Rows[0][3].ToString() + "<br/>"; mailBody += ds_PARAMETRICTESTSTATISTICTRIGGER.Tables[0].Rows[0][4].ToString(); mail.Send(mailTitle, mailBody); break; case "SITETOSITEPARAMETRICTESTSTATISTICDELTATRIGGER": mailTitle = sqlHelper.ExecuteScalar(@"select t1.action||'_'||t1.type||'_'||t1.product||'_'||t2.lotid||'_'||t2.testcod||'_'||t2.sblotid||'_'||t.eqname||'_'||to_char(t.rules_time,'yyyyMMddHHmmss') from sys_rules_show_ptr t left join sys_rules_testrun t1 on t.rules_guid=t1.guid left join mir t2 on t.stdfid=t2.stdfid where t.guid='" + prr_guid + "'").ToString(); DataSet ds_SITETOSITEPARAMETRICTESTSTATISTICDELTATRIGGER = sqlHelper.ExecuteDataSet(@"select t.rules_time,t1.action, '['||t1.type||'/'||t1.name||']:', 'LowLimit='||case t1.minstatus when '0' then t1.minvalue when '1' then t1.minvalue||'%' else 'null' end || ' HighLimit='||case t1.maxstatus when '0' then t1.maxvalue when '1' then t1.maxvalue||'%' else 'null' end || ' site='||t.sitenum||' value='||(to_number(NVL(substr(t.remark,instr(t.remark,'=',1,1)+1,instr(t.remark,',',1,1)-instr(t.remark,'=',1,1)-1),0))- to_number(NVL(substr(t.remark,instr(t.remark,'=',1,2)+1,instr(t.remark,',',1,2)-instr(t.remark,'=',1,2)-1),0)))||, 'MAX_site='||substr(t.remark,instr(t.remark,'=',1,3)+1,instr(t.remark,',',1,3)-instr(t.remark,'=',1,3)-1)|| ' MAX_value='||substr(t.remark,instr(t.remark,'=',1,1)+1,instr(t.remark,',',1,1)-instr(t.remark,'=',1,1)-1)|| ' MIN_site='||substr(t.remark,instr(t.remark,'=',1,4)+1,instr(t.remark,',',1,4)-instr(t.remark,'=',1,4)-1)|| ' MIN_value='||substr(t.remark,instr(t.remark,'=',1,2)+1,instr(t.remark,',',1,2)-instr(t.remark,'=',1,2)-1)|| ' GAP='||(to_number(NVL(substr(t.remark,instr(t.remark,'=',1,1)+1,instr(t.remark,',',1,1)-instr(t.remark,'=',1,1)-1),0))- to_number(NVL(substr(t.remark,instr(t.remark,'=',1,2)+1,instr(t.remark,',',1,2)-instr(t.remark,'=',1,2)-1),0))) from sys_rules_show_ptr t left join sys_rules_testrun t1 on t.rules_guid=t1.guid left join mir t2 on t.stdfid=t2.stdfid where t.guid='" + prr_guid + "'"); mailBody = ds_SITETOSITEPARAMETRICTESTSTATISTICDELTATRIGGER.Tables[0].Rows[0][0].ToString() + "," + ds_SITETOSITEPARAMETRICTESTSTATISTICDELTATRIGGER.Tables[0].Rows[0][1].ToString() + "<br/>"; mailBody += ds_SITETOSITEPARAMETRICTESTSTATISTICDELTATRIGGER.Tables[0].Rows[0][2].ToString() + "<br/>"; mailBody += ds_SITETOSITEPARAMETRICTESTSTATISTICDELTATRIGGER.Tables[0].Rows[0][3].ToString() + "<br/>"; mailBody += ds_SITETOSITEPARAMETRICTESTSTATISTICDELTATRIGGER.Tables[0].Rows[0][4].ToString(); mail.Send(mailTitle, mailBody); break; } }