예제 #1
0
 public void ProcessRequest(HttpContext context)
 {
     SPSecurity.RunWithElevatedPrivileges(() =>
     {
         Guid id = Guid.Empty;
         if (TryGuid(context.Request.QueryString["ID"], out id))
         {
             var file = EmailStorage.GetFile(id);
             if (file.Exists)
             {
                 context.Response.WriteFile(file.FullName);
             }
             else
             {
                 context.Response.Write("Maybe your email was deleted on server");
             }
         }
         else
         {
             context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
         }
     });
 }
예제 #2
0
        public bool OnNotification(SPAlertHandlerParams ahp)
        {
            try
            {
                Logger.WriteTrace("Start OnNotification" + Environment.NewLine + GetTrace(ahp), SharePointEmails.Logging.SeverityEnum.Trace);
                bool isNotificationHandled = false;

                using (SPSite site = new SPSite(ahp.siteId))
                {
                    using (SPWeb web = site.OpenWeb(ahp.webId))
                    {
                        if (!Application.Current.IsDisabledForFarm())
                        {
                            if (!Application.Current.IsDisabledForSite(site))
                            {
                                if (!Application.Current.IsDisabledForWeb(web))
                                {
                                    var mail = Application.Current.OnNotification(web, ahp);
                                    if (mail != null)
                                    {
                                        try
                                        {
                                            SPUtility.SendEmail(web, mail.headers, mail.HtmlBody);
                                            isNotificationHandled = true;
                                        }
                                        catch (Exception ex)
                                        {
                                            Logger.WriteTrace("Cannot send generated message", SharePointEmails.Logging.SeverityEnum.CriticalError);
                                            Logger.WriteTrace(ex, SharePointEmails.Logging.SeverityEnum.CriticalError);
                                        }

                                        try
                                        {
                                            EmailStorage.Add(mail.EventID, mail.HtmlBody);
                                            Logger.WriteTrace("Added to storage with key=" + mail.EventID, SharePointEmails.Logging.SeverityEnum.Verbose);
                                        }
                                        catch (Exception ex)
                                        {
                                            Logger.WriteTrace("Cannot add message to EmailStorage", SharePointEmails.Logging.SeverityEnum.CriticalError);
                                            Logger.WriteTrace(ex, SharePointEmails.Logging.SeverityEnum.CriticalError);
                                        }
                                    }
                                    else
                                    {
                                        Logger.WriteTrace("Mail is null", SharePointEmails.Logging.SeverityEnum.Warning);
                                    }
                                }
                                else
                                {
                                    Logger.WriteTrace("Disabled on web", SharePointEmails.Logging.SeverityEnum.Warning);
                                }
                                if (!isNotificationHandled)
                                {
                                    Logger.WriteTrace("Not handled. Send default message", SharePointEmails.Logging.SeverityEnum.Trace);
                                    return(SPUtility.SendEmail(web, ahp.headers, ahp.body));
                                }
                            }
                            else
                            {
                                Logger.WriteTrace("OnNotification - Application disabled on site collection", SharePointEmails.Logging.SeverityEnum.Verbose);
                            }
                        }
                        else
                        {
                            Logger.WriteTrace("OnNotification - Application disabled on farm", SharePointEmails.Logging.SeverityEnum.Verbose);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteTrace("ERROR OnNotification", SharePointEmails.Logging.SeverityEnum.CriticalError);
                Logger.WriteTrace(ex, SharePointEmails.Logging.SeverityEnum.CriticalError);
            }
            finally
            {
                Logger.WriteTrace("End OnNotification", SharePointEmails.Logging.SeverityEnum.Verbose);
            }
            return(false);
        }