public void AddMailTemplateUsageObject(string alertID, MailTemplateUsageObject mObject)
        {
            try
            {
                if (mailTemlateUsageList != null)
                {
                    SPListItem listItem = mailTemlateUsageList.AddItem();
                    listItem[ListAndFieldNames.MTUAlertFieldName]    = alertID + ";#" + alertID;
                    listItem[ListAndFieldNames.MTUTemplateFieldName] = mObject.Template.ID + ";#" + mObject.Template.Name;

                    //Event Type Registered
                    foreach (AlertEventType aType in mObject.AlertType)
                    {
                        listItem[ListAndFieldNames.settingsListEventTypeFieldName] += aType + ";#";
                    }


                    listItem[ListAndFieldNames.MTUHighLightUpdatedFieldsFieldName] = mObject.HighLightUpdatedFields;
                    listItem[ListAndFieldNames.MTUInsertAttachmentsFieldName]      = mObject.InsertAttachments;
                    listItem[ListAndFieldNames.MTUInsertUpdatedFieldsFieldName]    = mObject.InsertUpdatedFields;
                    listItem[ListAndFieldNames.MTUShareTemplateWithAllUsers]       = mObject.ShareTemplateWithAllUsers;

                    //Other information in xml format
                    listItem.Update();
                }
                else
                {
                    //unable to get mailtemplate usage list
                }
            }
            catch { }
        }
 private void CreateDelayedAlert(Alert alert, AlertEventType eventType, SPItemEventProperties properties, AlertManager alertManager)
 {
     //, SPWeb web
     try
     {
         if (!alert.SendAsSingleMessage)
         {
             Notifications notificationSender = new Notifications();
             //Need to get the Alert instances
             MailTemplateUsageObject mtObject = alert.GetMailTemplateUsageObjectForEventType(eventType);
             //string subject = mtObject.Template.Subject;
             //string body = mtObject.Template.Body + "<br>" + "<br>" + FinalBody;
             string       subject      = notificationSender.ReplacePlaceHolders(mtObject.Template.Subject, properties.ListItem);
             string       body         = notificationSender.ReplacePlaceHolders(mtObject.Template.Body, properties.ListItem) + "<br>" + "<br>" + FinalBody;
             string       parentItemId = Convert.ToString(properties.ListItem.ID);
             DelayedAlert dAlert       = new DelayedAlert(subject, body, alert.Id, parentItemId, eventType);
             alertManager.AddDelayedAlert(dAlert);
         }
         else
         {
             Notifications           notificationSender = new Notifications();
             MailTemplateUsageObject mtObject           = alert.GetMailTemplateUsageObjectForEventType(eventType);
             string       subject      = properties.ListTitle;
             string       body         = notificationSender.ReplacePlaceHolders(mtObject.Template.Subject, properties.ListItem) + "<br>" + "<br>" + notificationSender.ReplacePlaceHolders(mtObject.Template.Body, properties.ListItem) + "<br>" + "<br>" + FinalBody;
             string       parentItemId = Convert.ToString(properties.ListItem.ID);
             DelayedAlert dAlert       = new DelayedAlert(subject, body, alert.Id, parentItemId, eventType);
             alertManager.AddDelayedAlert(dAlert);
         }
     }
     catch { }
 }
        internal bool SendMail(Alert alert, AlertEventType eventType, SPListItem item, string strAfterProperties)
        {
            bool   succes = true;
            string body   = string.Empty;

            try
            {
                MailTemplateUsageObject mtObject          = alert.GetMailTemplateUsageObjectForEventType(eventType);
                List <Attachment>       attachmentsToSend = null;

                if (mtObject.Template.InsertAttachments)
                {
                    if (item.Attachments != null && item.Attachments.Count > 0)
                    {
                        if (attachmentsToSend == null)
                        {
                            attachmentsToSend = new List <Attachment>();
                        }

                        foreach (string fileName in item.Attachments)
                        {
                            SPFile file = item.ParentList.ParentWeb.GetFile(item.Attachments.UrlPrefix + fileName);
                            System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(file.OpenBinaryStream(), fileName, string.Empty);
                            attachmentsToSend.Add(attachment);
                        }
                    }
                }
                string toAddress   = GetRecipientEmailAddresses(alert.ToAddress, item);
                string ccAddress   = GetRecipientEmailAddresses(alert.CcAddress, item);
                string fromAddress = GetRecipientEmailAddresses(alert.FromAdderss, item);
                string subject     = ReplacePlaceHolders(mtObject.Template.Subject, item);
                if (mtObject.Template.InsertUpdatedFields)
                {
                    body = ReplacePlaceHolders(mtObject.Template.Body, item) + "<br>" + "<br>" + strAfterProperties;
                }
                else
                {
                    body = ReplacePlaceHolders(mtObject.Template.Body, item);
                }

                string smtpSName = GetSMTPServer(item);
                SendMail(smtpSName,
                         toAddress,
                         fromAddress,
                         ccAddress,
                         subject,
                         body,
                         attachmentsToSend);
            }
            catch { succes = false; }
            return(succes);
        }
        internal void SendDelayedMessage(DelayedAlert delayedAlert, Alert alert, SPListItem item)
        {
            try
            {
                MailTemplateUsageObject mtObject = alert.GetMailTemplateUsageObjectForEventType(delayedAlert.AlertType);
                string toAddress   = GetRecipientEmailAddresses(alert.ToAddress, item);
                string ccAddress   = GetRecipientEmailAddresses(alert.CcAddress, item);
                string fromAddress = GetRecipientEmailAddresses(alert.FromAdderss, item);
                string subject     = delayedAlert.Subject;
                string body        = delayedAlert.Body;
                //string subject = ReplacePlaceHolders(mtObject.Template.Subject, item);
                //string body = ReplacePlaceHolders(mtObject.Template.Body, item);
                string smtpSName = GetSMTPServer(item);
                SendMail(smtpSName,
                         toAddress,
                         fromAddress,
                         ccAddress,
                         subject,
                         body,
                         null);
            }
            catch { }
            //try
            //{
            //    SPListItem item = null;
            //    using (SPSite site = new SPSite(this.siteCollectionURL))
            //    {
            //        site.CatchAccessDeniedException = false;
            //        try
            //        {
            //            using (SPWeb web = site.OpenWeb(alert.WebId))
            //            {
            //               // item = ScanningUtilities.GetItemFromList(web, alert.ListId, delayedAlert.Item.ID);
            //                //if (item == null)
            //                {
            //                    item = delayedAlert.Item;
            //                }

            //            }
            //        }
            //        catch
            //        {
            //            item = delayedAlert.Item;
            //        }

            //    }
            //}
            //catch
            //{
            //}
        }
        internal MailTemplateUsageObject GetTemplateUsageObjectForAlert(string alertId, AlertEventType eventType)
        {
            MailTemplateUsageObject mObject = null;

            try
            {
                SPQuery query    = new SPQuery();
                string  strQuery = string.Format("<Where><And><Eq><FieldRef Name=\"{0}\"/><Value Type=\"Choice\">{1}</Value></Eq><Eq><FieldRef Name=\"Alert\" LookupId=\"TRUE\"/><Value Type=\"Lookup\">{2}</Value></Eq></And></Where>", "EventType", eventType.ToString(), alertId);
                query.Query = strQuery;
                SPListItemCollection listItemcollection = mailTemlateUsageList.GetItems(query);
                if (listItemcollection != null && listItemcollection.Count > 0)
                {
                    mObject = GetMailTemplateUsageObjectFromListItem(listItemcollection[0]);
                }
            }
            catch {}

            return(mObject);
        }
Esempio n. 6
0
        public void SendDelayedMessage2(DelayedAlert delayedAlert, Alert alert, SPListItem item)
        {
            Notifications notificationSender = new Notifications();

            try
            {
                MailTemplateUsageObject mtObject = alert.GetMailTemplateUsageObjectForEventType(delayedAlert.AlertType);
                toAddress   = notificationSender.GetRecipientEmailAddresses(alert.ToAddress, item);
                ccAddress   = notificationSender.GetRecipientEmailAddresses(alert.CcAddress, item);
                fromAddress = notificationSender.GetRecipientEmailAddresses(alert.FromAdderss, item);
                subject     = delayedAlert.Subject;
                body       += delayedAlert.Body;
                smtpSName   = notificationSender.GetSMTPServer(item);
                //SendMail(smtpSName,
                //         toAddress,
                //         fromAddress,
                //         ccAddress,
                //         subject,
                //         body,
                //         null);
            }
            catch { }
        }
        internal MailTemplateUsageObject GetMailTemplateUsageObjectFromListItem(SPListItem listItem)
        {
            MailTemplateUsageObject mObject        = new MailTemplateUsageObject();
            SPFieldLookupValue      lookupTempalte = new SPFieldLookupValue(listItem[ListAndFieldNames.MTUTemplateFieldName].ToString());
            SPListItem tListItem = mailTemplateList.GetItemById(lookupTempalte.LookupId);

            mObject.Template = GetMailTemplateFromListItem(tListItem);

            //Event Type Registered
            string strEventType = Convert.ToString(listItem[ListAndFieldNames.MTUEventTypeFieldName]);

            if (strEventType.Contains(AlertEventType.ItemAdded.ToString()))
            {
                mObject.AlertType.Add(AlertEventType.ItemAdded);
            }
            if (strEventType.Contains(AlertEventType.ItemDeleted.ToString()))
            {
                mObject.AlertType.Add(AlertEventType.ItemDeleted);
            }
            if (strEventType.Contains(AlertEventType.ItemUpdated.ToString()))
            {
                mObject.AlertType.Add(AlertEventType.ItemUpdated);
            }
            if (strEventType.Contains(AlertEventType.DateColumn.ToString()))
            {
                mObject.AlertType.Add(AlertEventType.DateColumn);
            }

            mObject.HighLightUpdatedFields    = Convert.ToBoolean(listItem[ListAndFieldNames.MTUHighLightUpdatedFieldsFieldName]);
            mObject.InsertAttachments         = Convert.ToBoolean(listItem[ListAndFieldNames.MTUInsertAttachmentsFieldName]);
            mObject.InsertUpdatedFields       = Convert.ToBoolean(listItem[ListAndFieldNames.MTUInsertUpdatedFieldsFieldName]);
            mObject.ShareTemplateWithAllUsers = Convert.ToBoolean(listItem[ListAndFieldNames.MTUShareTemplateWithAllUsers]);
            mObject.Created = Convert.ToString(listItem[ListAndFieldNames.createdBy]);

            return(mObject);
        }
        internal  MailTemplateUsageObject GetMailTemplateUsageObjectFromListItem(SPListItem listItem)
        {

            MailTemplateUsageObject mObject = new MailTemplateUsageObject();
            SPFieldLookupValue lookupTempalte = new SPFieldLookupValue(listItem[ListAndFieldNames.MTUTemplateFieldName].ToString());
            SPListItem tListItem = mailTemplateList.GetItemById(lookupTempalte.LookupId);
            mObject.Template = GetMailTemplateFromListItem(tListItem);

            //Event Type Registered
            string strEventType = Convert.ToString(listItem[ListAndFieldNames.MTUEventTypeFieldName]);
            if (strEventType.Contains(AlertEventType.ItemAdded.ToString()))
            {
                mObject.AlertType.Add(AlertEventType.ItemAdded);
            }
            if (strEventType.Contains(AlertEventType.ItemDeleted.ToString()))
            {
                mObject.AlertType.Add(AlertEventType.ItemDeleted);
            }
            if (strEventType.Contains(AlertEventType.ItemUpdated.ToString()))
            {
                mObject.AlertType.Add(AlertEventType.ItemUpdated);
            }
            if (strEventType.Contains(AlertEventType.DateColumn.ToString()))
            {
                mObject.AlertType.Add(AlertEventType.DateColumn);
            }

            mObject.HighLightUpdatedFields = Convert.ToBoolean(listItem[ListAndFieldNames.MTUHighLightUpdatedFieldsFieldName]);
            mObject.InsertAttachments = Convert.ToBoolean(listItem[ListAndFieldNames.MTUInsertAttachmentsFieldName]);
            mObject.InsertUpdatedFields = Convert.ToBoolean(listItem[ListAndFieldNames.MTUInsertUpdatedFieldsFieldName]);
            mObject.ShareTemplateWithAllUsers = Convert.ToBoolean(listItem[ListAndFieldNames.MTUShareTemplateWithAllUsers]);
            mObject.Created = Convert.ToString(listItem[ListAndFieldNames.createdBy]);

            return mObject;
        }
        public void AddMailTemplateUsageObject(string alertID, MailTemplateUsageObject mObject)
        {
            try
            {

                if(mailTemlateUsageList != null)
                {
                        SPListItem listItem = mailTemlateUsageList.AddItem();
                        listItem[ListAndFieldNames.MTUAlertFieldName] = alertID + ";#" +  alertID;
                        listItem[ListAndFieldNames.MTUTemplateFieldName] = mObject.Template.ID + ";#" + mObject.Template.Name;

                        //Event Type Registered
                        foreach (AlertEventType aType in mObject.AlertType)
                        {
                            listItem[ListAndFieldNames.settingsListEventTypeFieldName] += aType + ";#";
                        }


                        listItem[ListAndFieldNames.MTUHighLightUpdatedFieldsFieldName] = mObject.HighLightUpdatedFields;
                        listItem[ListAndFieldNames.MTUInsertAttachmentsFieldName] = mObject.InsertAttachments;
                        listItem[ListAndFieldNames.MTUInsertUpdatedFieldsFieldName] = mObject.InsertUpdatedFields;
                        listItem[ListAndFieldNames.MTUShareTemplateWithAllUsers] = mObject.ShareTemplateWithAllUsers;

                        //Other information in xml format
                        listItem.Update();

                }
                else
                {
                    //unable to get mailtemplate usage list
                }

            }
            catch { }
        }