andrewdavey / andrewdavey/postal

Email send fails when no HttpContext is available in ASP MVC application

未關閉
#73 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
C#
星號
534
分支
164
PR 合併指標
30 天內沒有已合併 PR

描述

Hello!

I'm using Postal in one of my personal projects and find it very useful! However recently I've encountered a minor issue which I think is a bug in current version (I've tried latest 0.9.2 release).
I want to use email views and models of ASP MVC web application in two different scenarios. First is widespread - to send email from controller action method by using `Email.Send()`. Second is more tricky and it lead to the issue - to send email from background thread by using same method `Email.Send()`.
Actual problem is `ArgumentException` occuring in `Email.Send()` and originating from `System.Web.CachedPathData.GetVirtualPathData()`. Issue manifests only if web application root doesn't match the web site root, e.g. web application is located at _http://mydomain.com/MyApp/_, not in _http://mydomain.com/_.
Problem source is in method `EmailViewRenderer.UrlRoot()`, where `System.Web.VirtualPathUtility` can be used to generate correct application root url if `HttpContext.Current` is undefined instead of simply return _http://localhost_.
Now I init `HttpContext.Current` manually before calling `Email.Send()` as a workaround.

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。