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", "xyz@abc.com");
                                headers.Add("bcc", "");
                                headers.Add("from", "email@add.com");
                                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);
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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