You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to send emails using Hangfire and Postal, but I'm having problems with the HTTPContext. If I execute the shooting through a controller the sending is done without problems, now if I execute a job via Hangfire an expection is generated.
There is no HttpContext can be retrieved in background since it is not a http request when Hangfire execute the job. That's why we need the Postal.RequestPath class to create the DefaultHttpContext object in Postal library.
@tiagosarri Best way around this is to create the email using Postal and then to serialise it so that hangfire can de-serialise it. Using the smtp client you can then construct a MailMessage which will then allow you to send emails via HangFire.
@tiagosarri alternatively simply get what you need out of the httpcontext and pass it as a parameter to the method that creates your email, and use the param instead of the context inside your email. ie:
I'm trying to send emails using Hangfire and Postal, but I'm having problems with the HTTPContext. If I execute the shooting through a controller the sending is done without problems, now if I execute a job via Hangfire an expection is generated.
Code startup.cs
Code NotificationServices.cs
The error is in HttpContext: _httpContextAccessor.HttpContext.Request.PathBase.ToString()
Object reference not set to an instance of an object
Is it possible to send e-mails via background with Postal?
The text was updated successfully, but these errors were encountered: