1

My timer job is sending emails perfectly in local machine where I have developed it based on a configuration list. When I moved it to the Development environment(No Visual Studio), It is not sending emails.

But, in the Job History, I can see the Job status as "succeeded". Please help.

            StringDictionary messageHeaders = new StringDictionary();
            messageHeaders.Add("To", to);
            if (!string.IsNullOrEmpty(cc))
                messageHeaders.Add("CC", cc);
            messageHeaders.Add("Subject", subject);
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite newsite = new SPSite(webUrl))
                {
                    using (SPWeb newweb = newsite.OpenWeb())
                    {
                        SPUtility.SendEmail(newweb, messageHeaders, body);
                    }
                }
            });
  • Can you share the code you use to send emails? Do you have try/catch blocks? – Evariste Mar 29 '16 at 16:38
  • Hi Evariste, I have added try catch blocks. Added the code – Jeevana Mar 29 '16 at 16:44
1

Couples of things to check:

  • Outgoing Email is properly configured in that farm. if not then this is the reason.
  • try to setup an alert on any of list and see if you get the notification.
  • Check the Immediate alerts job is working.
  • lastly, check the ULS logs and Event log for more clue.
  • Hi Sarwar, I received the mail when granted permissions to myself on one of the list. I can see the Immediate Alert's Last run time as current time. I found no errors in Logs. – Jeevana Mar 29 '16 at 16:09
  • try to set alert on the library then add the document and see if you get alert on adding? also check your code, if you hardcoded any url which points to dev server? – Waqas Sarwar MVP Mar 29 '16 at 16:12
  • I have added an alert which send email when new item is added. I got emails when I added new Items. In ULS logs I got below error ItemAdded: >=message=> Object reference not set to an instance of an object. >=stacktrace=> at Sharepoint.APAC.APACtimerJob.<>c__DisplayClass2.<Execute>b__0() at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) – Jeevana Mar 29 '16 at 16:43
0

Some comments:

  • SPSecurity.RunWithElevatedPrivileges is not needed at all in the context of a job, that already runs Under the SPFarm identity.
  • Are you 100% sure the to variable is properly set?
  • According to the stack trace you submitted in a comment, an error is raised before you even try to send an email. IMO your problem is not related to the email but Something else before it.
  • The error you have states "ItemAdded" and "Object reference not set to an instance of an object". This makes me think you also have an event receiver (ER) plugged on a list you add an item to from the job. One common issue I see very often in ER, and that leads to an "Object reference not set..." error is using SPContext.Current in the ER; SPContext.Current is null when the ER is fired from Something else than a Web context (i.e. a job).

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.