Esempio n. 1
0
        public static SEMessage Create(SPEmailMessage mail)
        {
            var res = new SEMessage();

            res.inner = mail;
            foreach (var i in mail.Headers)
            {
                res.headers.Add(i.Name, i.Value);
            }
            res.PlainBody = mail.PlainTextBody;
            res.HtmlBody  = mail.HtmlBody;
            res.Sender    = mail.Sender;
            return(res);
        }
        /// <summary>
        /// The list received an e-mail message.
        /// </summary>
        public override void EmailReceived(SPList list, SPEmailMessage emailMessage, String receiverData)
        {
            //  Specify log list name
            string listName = "ListEmailEventLogger";

            //  Create the string builder object
            StringBuilder sb = new StringBuilder();

            //  Add the email message properties
            sb.AppendFormat("From:\t {0}\n", emailMessage.Sender);
            sb.AppendFormat("To:\t {0}\n", emailMessage.Headers["To"]);
            sb.AppendFormat("Subject:\t {0}\n", emailMessage.Headers["Subject"]);
            sb.AppendFormat("Body:\t {0}\n", emailMessage.PlainTextBody);

            //  Log the event to the list
            Common.LogEvent(list.ParentWeb, listName, SPEventReceiverType.EmailReceived, sb.ToString());
        }
        public override void EmailReceived(SPList list, SPEmailMessage emailMessage, String receiverData)
        {
            base.EmailReceived(list, emailMessage, receiverData);
            SPListItem item = list.Items.Add();
            item["Title"] = emailMessage.Headers["Subject"];
            item["Body"] = emailMessage.HtmlBody;
            item["EmailFrom"] = emailMessage.Sender;
            item.Update();

            using (SPSite site = new SPSite(list.ParentWeb.Site.Url, list.ParentWeb.Site.SystemAccount.UserToken))
            {
                using (SPWeb webSA = site.OpenWeb())
                {
                    string Status = string.Empty;
                    string Body = emailMessage.HtmlBody;
                    if (Body.ToLower().Contains("approve") || Body.ToLower().Contains("approved"))
                        Status = "Approve";
                    else if (Body.ToLower().Contains("reject") || Body.ToLower().Contains("rejected"))
                        Status = "Reject";

                    if (Status != string.Empty)
                    {
                        Regex r;
                        Match m;
                        string url = string.Empty;
                        int ID = 0;
                        r = new Regex("href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))", RegexOptions.IgnoreCase | RegexOptions.Compiled);
                        for (m = r.Match(Body); m.Success; m = m.NextMatch())
                        {
                            if (m.Groups[1].ToString().Contains("ID="))
                                url = m.Groups[1].ToString();
                        }

                        if (url != string.Empty)
                        {
                            Uri tempUri = new Uri(string.Format("http://sharepoint{0}", url));
                            string sQuery = tempUri.Query;
                            ID = Convert.ToInt32(HttpUtility.ParseQueryString(sQuery).Get("ID"));
                        }

                        if (ID != 0)
                        {
                            try
                            {
                                webSA.AllowUnsafeUpdates = true;
                                SPList taskList = webSA.Lists["Tasks"];
                                SPListItem taskItem = taskList.GetItemById(ID);

                                Hashtable taskData = new Hashtable();
                                taskData.Add("PercentComplete", 1);
                                taskData.Add("Completed", true);
                                taskData.Add("ApproveOrReject", Status);
                                taskData.Add("Status", "Completed");
                                taskData.Add("Remarks", string.Empty);
                                SPWorkflowTask.AlterTask(taskItem, taskData, true);
                                taskItem.Update();

                                if (taskItem["ParentID"] != null)
                                {
                                    SPListItem taskItemParent = taskList.GetItemById(Convert.ToInt32(taskItem["ParentID"].ToString()));
                                    SPWorkflowTask.AlterTask(taskItemParent, taskData, true);
                                    taskItemParent.Update();
                                }
                                webSA.AllowUnsafeUpdates = false;
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// The list received an e-mail message.
 /// </summary>
 public override void EmailReceived(SPList list, SPEmailMessage emailMessage, String receiverData)
 {
     base.EmailReceived(list, emailMessage, receiverData);
 }
Esempio n. 5
0
 public override void EmailReceived(SPList list, SPEmailMessage emailMessage, string receiverData)
 {
     Application.Current.OnIncomingMail(list, emailMessage);
 }