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);