0

I need to create a timerjob which should send/trigger mail to manager 2 days before end date as a reminder

class CustomTimerJob : SPJobDefinition
    {
        public CustomTimerJob() : base()
        { 
        }

        public CustomTimerJob(string jobName, SPService service,SPServer server,SPJobLockType targettype) : base(jobName, service, server, targettype)
        {
            this.Title = "Task Complete Timer";
        }

        public CustomTimerJob(string jobName, SPWebApplication webapplication) : base(jobName, webapplication, null, SPJobLockType.Job)
        {
            this.Title = "Task Complete Timer";
        }

        public override void Execute(Guid targetInstanceId)
        {
            SPWebApplication webapplication = (SPWebApplication)this.Parent;


            foreach (SPSite site in webapplication.Sites)
            {
                  try
                {

                    foreach (SPWeb subWebapp in site.AllWebs)
                    {
                        try
                        {
                            SPList list = subWebapp.Lists.TryGetList("Details");

                            SPQuery query = new SPQuery()
                            {
                                Query = "Your query that check if field empty",
                                ViewAttributes = "Scope=\"Recursive\""
                            };
                            var items = list.GetItems(query);
                            foreach (SPListItem item in items)
                            {

                                string messagebody = "your message body";
                                //
                                StringDictionary headers = new StringDictionary();
                                headers.Add("to", subWebapp.Web.CurrentUser.Email);
                                headers.Add("cc", "[email protected]");
                                headers.Add("bcc", "");
                                headers.Add("from", "[email protected]");
                                headers.Add("subject", "Email Subject");
                                headers.Add("content-type", "text/html");
                                string bodyText = "Hello how are you?";
                                SPUtility.SendEmail(subWebapp, headers, messagebody);
                            }
                        }
                        finally
                        {
                            subWebapp.Dispose();
                        }
                    }
                }
                finally
                {
                    site.Dispose();
                }
            }
        }
    }
}

I'm getting this error

'Microsoft.SharePoint.SPWeb' does not contain a definition for 'Web' and no extension method 'Web' accepting a first argument of type 'Microsoft.SharePoint.SPWeb' could be found (are you missing a using directive or an assembly reference?)

error in the below line at Web

headers.Add("to", subWebapp.Web.CurrentUser.Email);
9
  • What did you try so far? Commented Oct 19, 2015 at 14:09
  • i have tried this code as below
    – user47980
    Commented Oct 20, 2015 at 5:47
  • Where is your code? Commented Oct 20, 2015 at 5:50
  • code is not readable in comment. Add it in your question Commented Oct 20, 2015 at 5:55
  • i have edited plz check
    – user47980
    Commented Oct 20, 2015 at 6:02

1 Answer 1

0

If I understand your point correct, you have a list or library. Within this list there is a column end date and you want to send a reminder for each item in the list two days before its end date.

In this case I think a SharePoint Designer workflow connected to this list would be the best and easiest option.

I have currently not the chance to have a look into a SharePoint Designer, but from my mind the workflow should look something like this:

Workflow should be started automatically on item creation (you can also think about on item edit, depending on your needs)

Define a workflow variable "duedate".

Set workflow variable "duedate" to end date of list item minus 2 days.

Add a condition to check if duedate is larger than [today].

If yes, pause workflow until duedate.

Add an action "Send email". You can select the manager of the author of the current item (or of any other person field in the list) as recipient, if the manager attribute is filled in the user profile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.