I’m using Hangfire to process a time consuming job. Its working well, but the problem is I need to send notifications after the job is finished. For that I used SMTPClient at the end of this method to shoot out an email once completed. The job is succeeded but there is no email. I’m not sure what the issue is.
Technology background: The actual job method and hangfire methods are residing in two seperate WCF service layer. TaskShceduler is a WCF service that enqueue items for hangfire processor. And internally the enqueued method is calling another WCF to process the actual job.
public void EnqueueMergeTask(some params)
BackgroundJob.Enqueue(() => EnqueueItems(items, Filters, notificationEmail));
public void EnqueueItems(List items, Dictionary<string, List> Filters, string notificationEmail)
// calls another WCF method
SPOperations.MergeReportData(items, Filters, notificationEmail);
public void MergeReportData(List ietms, Dictionary<string, List> Filters, string notificationEmail)
MailMessage msg = new MailMessage(fromaddr, toaddr, "Merge Reports Task status", body); msg.IsBodyHtml = true; SmtpClient smtp = new SmtpClient( "XXX.XXX.XXX.XXX"); smtp.Send(msg);
For some reasons the mail is not send out. Job is getting processed, no exceptions and I’m getting the actual output except for the email part. The same code works when I call the method directly NOT using hangfire. so i’m not sure if there anything else that I should be aware of in this case.
Appreciate the help!