internal static void SendBroadcastMessage(int messageId, string text) { if (!AlertsEnabled) return; ArrayList users = new ArrayList(); using (IDataReader reader = DbAlert2.GetBroadcastRecipients(messageId)) { while (reader.Read()) { UserInfo ui = new UserInfo(); ui.ImId = (int)reader["ImId"]; ui.Locale = reader["Locale"].ToString(); users.Add(ui); } } ArrayList vars = new ArrayList(); AddVariableInitiatedBy(vars); vars.Add(new VariableInfo(new AlertVariable(Variable.Text), text, true)); Hashtable messages = new Hashtable(); foreach (UserInfo ui in users) { string message = (string)messages[ui.Locale]; if (message == null) { string subject, body; AlertTemplate.GetTemplate(AlertTemplateTypes.Special, ui.Locale, SpecialMessageType.BroadcastMessage.ToString(), true, out subject, out body); Message msg = GetMessage(subject, body, ui, vars, -1, -1, null); message = msg.Body; messages[ui.Locale] = message; } try { SendMessage(DeliveryType.IBN, ui.GetAddress(DeliveryType.IBN), message, null); } catch (Exception ex) { Log.WriteError(ex.ToString()); } } }
internal static void SendForgottenPassword(int userId, string logonLink) { if (!AlertsEnabled) return; UserInfo ui = new UserInfo(); ui.Load(userId); ArrayList vars = new ArrayList(); vars.Add(new VariableInfo(new AlertVariable(Variable.LogonLink, true, false), logonLink)); string subject, body; AlertTemplate.GetTemplate(AlertTemplateTypes.Special, ui.Locale, SpecialMessageType.ForgottenPassword.ToString(), true, out subject, out body); Message msg = GetMessage(subject, body, ui, vars, -1, -1, null); try { SendMessage(DeliveryType.Email, ui.GetAddress(DeliveryType.Email), msg.Body, msg.Subject); } catch (Exception ex) { Log.WriteError(ex.ToString()); throw; } }
private static void SendBatch(UserInfo ui, DeliveryType deliveryType, Message msg) { try { //Attachment[] attachments = null; //if (deliveryType == DeliveryType.Email) // attachments = (Attachment[])msg.Attachments.ToArray(typeof(Attachment)); using (DbTransaction tran = DbTransaction.Begin()) { SendMessage(deliveryType, ui.EmailFrom, ui.GetAddress(deliveryType), msg.Body, msg.Subject/*, attachments*/); foreach (RecipientInfo ri in ui.Recipients) { DBSystemEvents.RecipientUpdateSent(ri.RecipientId, (int)deliveryType, true); } tran.Commit(); } } catch (Exception ex) { Log.WriteError(ex.ToString()); } }