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
            //{
            //}
        }
Beispiel #4
0
        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 
            //{
            //}
        }
        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 { }
        }
Beispiel #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 { }
 }
 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 { }
 }
Beispiel #8
0
        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;
        }