/// ///////////////////////////////////////////////////////// protected override CResultAErreur MyExecute(CContexteExecutionAction contexte) { CResultAErreur result = CResultAErreur.True; string strExpediteur = ""; string strSujet = ""; string strMessage = ""; ArrayList lstDestinataires = new ArrayList(); ArrayList lstDestinatairesCC = new ArrayList(); ArrayList lstDestinatairesBCC = new ArrayList(); ArrayList lstIdsDocs = new ArrayList(); CContexteEvaluationExpression contexteEval = new CContexteEvaluationExpression(contexte.Branche.Process); if (m_formuleAdresseExpediteur == null) { result.EmpileErreur(I.T("Incorrect Sender adress formula|389")); return(result); } result = m_formuleAdresseExpediteur.Eval(contexteEval); if (!result) { result.EmpileErreur(I.T("Error during evaluation of the recipient address|399")); return(result); } strExpediteur = GetMail(result.Data); if (m_formuleSujet == null) { result.EmpileErreur(I.T("Incorrect subject formula|391")); return(result); } result = m_formuleSujet.Eval(contexteEval); if (!result) { result.EmpileErreur(I.T("Error during mail subject evaluation|400")); return(result); } strSujet = result.Data.ToString(); if (m_formuleMessage == null) { result.EmpileErreur(I.T("The message formula is false|393")); return(result); } result = m_formuleMessage.Eval(contexteEval); if (!result) { result.EmpileErreur(I.T("Error during mail content evaluation|401")); return(result); } strMessage = result.Data.ToString(); // Traite les destinataires To foreach (C2iExpression exp in m_listeFormulesMailsDestinatairesTo) { if (exp != null) { result = exp.Eval(contexteEval); if (!result) { result.EmpileErreur(I.T("Error while evaluating one of the recipients|402")); return(result); } object res = result.Data; if (res is string) { res = ((string)res).Split(new char[] { ';', ',' }); } if (res is IList) { foreach (object obj in ((IList)res)) { string strMail = GetMail(obj); if (strMail.Trim() != "") { lstDestinataires.Add(strMail); } } } else if (res.ToString().Trim() != "") { string strMail = GetMail(res); if (strMail.Trim() != "") { lstDestinataires.Add(strMail); } } } } // Traite les destinataires CC foreach (C2iExpression exp in m_listeFormulesMailsDestinatairesCC) { if (exp != null) { result = exp.Eval(contexteEval); if (!result) { result.EmpileErreur(I.T("Error while evaluating one of the recipients|402")); return(result); } object res = result.Data; if (res is string) { res = ((string)res).Split(new char[] { ';', ',' }); } if (res is IList) { foreach (object obj in ((IList)res)) { string strMail = GetMail(obj); if (strMail.Trim() != "") { lstDestinatairesCC.Add(strMail); } } } else if (res.ToString().Trim() != "") { string strMail = GetMail(res); if (strMail.Trim() != "") { lstDestinatairesCC.Add(strMail); } } } } // Traite les destinataires BCC foreach (C2iExpression exp in m_listeFormulesMailsDestinatairesBCC) { if (exp != null) { result = exp.Eval(contexteEval); if (!result) { result.EmpileErreur(I.T("Error while evaluating one of the recipients|402")); return(result); } object res = result.Data; if (res is string) { res = ((string)res).Split(new char[] { ';', ',' }); } if (res is IList) { foreach (object obj in ((IList)res)) { string strMail = GetMail(obj); if (strMail.Trim() != "") { lstDestinatairesBCC.Add(strMail); } } } else if (res.ToString().Trim() != "") { string strMail = GetMail(res); if (strMail.Trim() != "") { lstDestinatairesBCC.Add(strMail); } } } } // Traite les pièces jointes foreach (C2iExpression exp in m_listeFormulesPiecesJointes) { if (exp != null) { result = exp.Eval(contexteEval); if (!result) { result.EmpileErreur(I.T("Error while evaluating one of the recipients|402")); return(result); } if (result.Data is IEnumerable) { foreach (object obj in ((IList)result.Data)) { if (obj is CDocumentGED) { lstIdsDocs.Add(((CDocumentGED)obj).Id); } } } else if (result.Data is CDocumentGED) { lstIdsDocs.Add(((CDocumentGED)result.Data).Id); } } } // Genere le Mail string[] destArray = (string[])lstDestinataires.ToArray(typeof(string)); string[] destCCArray = (string[])lstDestinatairesCC.ToArray(typeof(string)); string[] destBCCArray = (string[])lstDestinatairesBCC.ToArray(typeof(string)); int[] docsArray = (int[])lstIdsDocs.ToArray(typeof(int)); CMailSC2I mail = new CMailSC2I( strExpediteur, strSujet, strMessage, destArray, destCCArray, destBCCArray, docsArray, IsFormatHTML, UseDocLabelAsFileName, SMTPserver, SMTPort, SMTPUser, SMTPPassword); // Envoi le mail IExpediteurMail expediteur = (IExpediteurMail)C2iFactory.GetNewObjetForSession("CExpediteurMail", typeof(IExpediteurMail), contexte.IdSession); result = expediteur.SendMail(mail); return(result); }
public static void SendMails(List <CEvenementAlarm> lstEvents, CContexteDonnee ctxDonnee) { /* * foreach (CEvenementAlarm eventAl in lstEvents) * { * if (eventAl.CategorieMessageAlarme == ECategorieMessageAlarme.AlarmStartStop) * { * if (eventAl.EventAlarmStartStop.AlarmInfo.SeverityCode == (int)EGraviteAlarmeAvecMasquage.EndAlarm) * continue; * * CListeObjetsDonnees lstConsult = new CListeObjetsDonnees(ctxDonnee, typeof(CConsultationAlarmesEnCoursInDb)); * lstConsult.Filtre = new CFiltreDataAvance(CConsultationAlarmesEnCoursInDb.c_nomTable, * CConsultationAlarmesEnCoursInDb.c_champActiverEMail + " = 1 and Has( Emails." + * CParamlArmEC_EMail.c_champParamAlarmECId + " )", null); * * foreach (CConsultationAlarmesEnCoursInDb consult in lstConsult) * { * int id = consult.Id;//test * if (consult.Parametres.FormuleFiltre != null) * { * CContexteEvaluationExpression contexte = new CContexteEvaluationExpression(eventAl.EventAlarmStartStop.AlarmInfo); * if (!consult.Parametres.FormuleFiltre.Eval(contexte)) * continue; * } * * List<string> lstColumnNames = new List<string>(); * ArrayList arrayData = new ArrayList(); * StringBuilder stblMessage = new StringBuilder(); * string [] arrayDest; * string stSubject; * string stSender; * string st; * int i = 0; * * lstColumnNames = consult.Parametres.GetColumnNames(); * arrayData = consult.Parametres.GetDataToDisplay(eventAl.EventAlarmStartStop.AlarmInfo); * * foreach(string stColumnName in lstColumnNames) * { * st = stColumnName + " : " + arrayData[i]; * stblMessage.AppendLine(st); * i++; * } * * stSubject = I.T("Alarm @1|60000", eventAl.EventAlarmStartStop.AlarmInfo.AlarmeGeree.Name); * * arrayDest = new string[consult.Emails.Count]; * i=0; * foreach(CParamlArmEC_EMail paramlArmEC_EMail in consult.Emails) * { * arrayDest[i] = paramlArmEC_EMail.Email; * i++; * } * * IDatabaseRegistre registre = (IDatabaseRegistre)C2iFactory.GetNew2iObjetServeur(typeof(IDatabaseRegistre), ctxDonnee.IdSession); * stSender = (string)registre.GetValeurString("SENDER_ADDRESS",""); * * int[] docsArray = new int[0]; * CMailSC2I mail = new CMailSC2I(stSender, stSubject, stblMessage.ToString(), * arrayDest, docsArray); * * IExpediteurMail expediteur = (IExpediteurMail)C2iFactory.GetNewObjetForSession("CExpediteurMail", typeof(IExpediteurMail), ctxDonnee.IdSession); * CResultAErreur result = expediteur.SendMail(mail); * } * } * } * }*/ foreach (CEvenementAlarm eventAlarme in lstEvents) { if (eventAlarme.GetType() == typeof(CEvenementAlarmStartStop)) { CEvenementAlarmStartStop eventAl = (CEvenementAlarmStartStop)eventAlarme; if (eventAl.Gravite == EGraviteAlarmeAvecMasquage.EndAlarm) { continue; } CInfoAlarmeAffichee infoAlarmeAffichee = new CInfoAlarmeAffichee(eventAl); CListeObjetsDonnees lstConsult = new CListeObjetsDonnees(ctxDonnee, typeof(CConsultationAlarmesEnCoursInDb)); lstConsult.Filtre = new CFiltreDataAvance(CConsultationAlarmesEnCoursInDb.c_nomTable, CConsultationAlarmesEnCoursInDb.c_champActiverEMail + " = 1 and Has( Emails." + CParamlArmEC_EMail.c_champParamAlarmECId + " )", null); foreach (CConsultationAlarmesEnCoursInDb consult in lstConsult) { int id = consult.Id;//test if (consult.Parametres.FormuleFiltre != null) { CContexteEvaluationExpression contexte = new CContexteEvaluationExpression(infoAlarmeAffichee); if (!consult.Parametres.FormuleFiltre.Eval(contexte)) { continue; } } List <string> lstColumnNames = new List <string>(); ArrayList arrayData = new ArrayList(); StringBuilder stblMessage = new StringBuilder(); string[] arrayDest; string stSubject; string stSender; string st; int i = 0; lstColumnNames = consult.Parametres.GetColumnNames(); arrayData = consult.Parametres.GetDataToDisplay(infoAlarmeAffichee); foreach (string stColumnName in lstColumnNames) { st = stColumnName + " : " + arrayData[i]; stblMessage.AppendLine(st); i++; } stSubject = I.T("Alarm @1|60000", eventAl.NomAlarmeGeree); arrayDest = new string[consult.Emails.Count]; i = 0; foreach (CParamlArmEC_EMail paramlArmEC_EMail in consult.Emails) { arrayDest[i] = paramlArmEC_EMail.Email; i++; } IDatabaseRegistre registre = (IDatabaseRegistre)C2iFactory.GetNew2iObjetServeur(typeof(IDatabaseRegistre), ctxDonnee.IdSession); stSender = (string)registre.GetValeurString("SENDER_ADDRESS", m_strExpMailParDefaut); int[] docsArray = new int[0]; CMailSC2I mail = new CMailSC2I(stSender, stSubject, stblMessage.ToString(), arrayDest, null, null, docsArray); IExpediteurMail expediteur = (IExpediteurMail)C2iFactory.GetNewObjetForSession("CExpediteurMail", typeof(IExpediteurMail), ctxDonnee.IdSession); CResultAErreur result = expediteur.SendMail(mail); } } } }