MvcMailer icon indicating copy to clipboard operation
MvcMailer copied to clipboard

Logging issues

Open Eonasdan opened this issue 12 years ago • 8 comments

I want to log the messages that are sent out. I was doing this:

public virtual MvcMailMessage PasswordReset(string emailTo, string passwordToken)
    {
        ViewBag.passwordToken = passwordToken;

        var mailer = Populate(x =>
        {
            x.Subject = "Password Reset";
            x.ViewName = "PasswordReset";
            x.To.Add(emailTo);
        });
        GeneralHelpers.LogEmail(mailer.Subject, mailer.Body, mailer.To.ToString()); //custom function to save the details to a db
        return mailer;
    }

but I usually get Value does not fall within the expected range. at the var mailer line

If I change me code to this:

public virtual MvcMailMessage PasswordReset(string emailTo, string passwordToken)
    {
        ViewBag.passwordToken = passwordToken;

       return Populate(x =>
        {
            x.Subject = "Password Reset";
            x.ViewName = "PasswordReset";
            x.To.Add(emailTo);
        });
    }

It works, but I don't get any logging.

Eonasdan avatar Nov 19 '12 13:11 Eonasdan

Please include a stack trace so we can dig deeper into this.


Sent from my iPhone Sohan SM

On 2012-11-19, at 6:07 AM, Eonasdan [email protected] wrote:

I want to log the messages that are sent out. I was doing this:

public virtual MvcMailMessage PasswordReset(string emailTo, string passwordToken) { ViewBag.passwordToken = passwordToken;

    var mailer = Populate(x =>
    {
        x.Subject = "Password Reset";
        x.ViewName = "PasswordReset";
        x.To.Add(emailTo);
    });
    GeneralHelpers.LogEmail(mailer.Subject, mailer.Body,

mailer.To.ToString()); return mailer; }

but I usually get Value does not fall within the expected range. at the var mailer line

If I change me code to this:

public virtual MvcMailMessage PasswordReset(string emailTo, string passwordToken) { ViewBag.passwordToken = passwordToken;

   return mailer = Populate(x =>
    {
        x.Subject = "Password Reset";
        x.ViewName = "PasswordReset";
        x.To.Add(emailTo);
    });
}

It works, but I don't get any logging.

— Reply to this email directly or view it on GitHubhttps://github.com/smsohan/MvcMailer/issues/71.

smsohan avatar Nov 19 '12 14:11 smsohan

In the controller I'm doing this:

UserMailer.PasswordReset(userEmail, token).Send();

UserMailer:

public interface IUserMailer
{
    [...]
     MvcMailMessage PasswordReset(string emailTo, string passwordToken);
}

Stack:

    System.ArgumentException occurred
    HResult=-2147024809
   Message=Value does not fall within the expected range.
   Source=mscorlib
   StackTrace:
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
       at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
       at System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name)
       at System.Web.Hosting.IIS7WorkerRequest.GetRemoteAddress()
       at System.Web.HttpWorkerRequest.IsLocal()
       at System.Web.HttpRequestWrapper.get_IsLocal()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       at System.Web.WebPages.StartPage.RunPage()
       at System.Web.WebPages.StartPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       at Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context)
       at Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context, String mailerName)
       at Mvc.Mailer.MailerBase.EmailBody(String viewName, String masterName)
       at Mvc.Mailer.MailerBase.PopulateHtmlBody(MailMessage mailMessage, String viewName, String masterName)
       at Mvc.Mailer.MailerBase.PopulateBody(MailMessage mailMessage, String viewName, String masterName, Dictionary`2 linkedResources)
       at Mvc.Mailer.MailerBase.Populate(Action`1 action)
       at projectMgt.Mailers.UserMailer.PasswordReset(String emailTo, String passwordToken) in Mailers\UserMailer.cs:line 96
    InnerException: 

Elmah shows the stack as:

        System.ArgumentException occurred
    HResult=-2147024809
   Message=Value does not fall within the expected range.
   Source=mscorlib
   StackTrace:
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
       at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
       at System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name)
       at System.Web.Hosting.IIS7WorkerRequest.GetRemoteAddress()
       at System.Web.HttpWorkerRequest.IsLocal()
       at System.Web.HttpRequestWrapper.get_IsLocal()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
       at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
       at System.Web.WebPages.StartPage.RunPage()
       at System.Web.WebPages.StartPage.ExecutePageHierarchy()
       at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
       at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
       at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
       at Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context)
       at Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context, String mailerName)
       at Mvc.Mailer.MailerBase.EmailBody(String viewName, String masterName)
       at Mvc.Mailer.MailerBase.PopulateHtmlBody(MailMessage mailMessage, String viewName, String masterName)
       at Mvc.Mailer.MailerBase.PopulateBody(MailMessage mailMessage, String viewName, String masterName, Dictionary`2 linkedResources)
       at Mvc.Mailer.MailerBase.Populate(Action`1 action)
       at projectMgt.Mailers.UserMailer.PasswordReset(String emailTo, String passwordToken) in Mailers\UserMailer.cs:line 96
    InnerException: `enter code here`

Line 96 is where return Populate.... is

I thought I had it fixed as I mentioned above but it seems to be hit and miss. Some times it works and other times it doesn't

Eonasdan avatar Nov 19 '12 14:11 Eonasdan

It appears that in the view file there is something that's making the Razor engine to fail rendering. Can you start with a dumb view, may be just some plain text without variables/dynamic contents?


Sent from my iPhone Sohan SM

On 2012-11-19, at 7:47 AM, Eonasdan [email protected] wrote:

In the controller I'm doing this:

UserMailer.PasswordReset(userEmail, token).Send();

UserMailer:

public interface IUserMailer { [...] MvcMailMessage PasswordReset(string emailTo, string passwordToken); }

Stack:

System.ArgumentException occurred HResult=-2147024809 Message=Value does not fall within the expected range. Source=mscorlib StackTrace: at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name) at System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name) at System.Web.Hosting.IIS7WorkerRequest.GetRemoteAddress() at System.Web.HttpWorkerRequest.IsLocal() at System.Web.HttpRequestWrapper.get_IsLocal() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() at System.Web.WebPages.StartPage.RunPage() at System.Web.WebPages.StartPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) at Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context) at Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context, String mailerName) at Mvc.Mailer.MailerBase.EmailBody(String viewName, String masterName) at Mvc.Mailer.MailerBase.PopulateHtmlBody(MailMessage mailMessage, String viewName, String masterName) at Mvc.Mailer.MailerBase.PopulateBody(MailMessage mailMessage, String viewName, String masterName, Dictionary2 linkedResources) at Mvc.Mailer.MailerBase.Populate(Action1 action) at projectMgt.Mailers.UserMailer.PasswordReset(String emailTo, String passwordToken) in Mailers\UserMailer.cs:line 96 InnerException:

Line 96 is where return Populate.... is

I thought I had it fixed as I mentioned above but it seems to be hit and miss. Some times it works and other times it doesn't

— Reply to this email directly or view it on GitHubhttps://github.com/smsohan/MvcMailer/issues/71#issuecomment-10515914.

smsohan avatar Nov 19 '12 15:11 smsohan

I took everything out of the View I was using to be this:

You (hopefully) have requested a password reset for [..]. 
Please proceed to the <a href="" >password reset page</a> or copy this link into your browser:

Eonasdan avatar Nov 19 '12 15:11 Eonasdan

Is this still failing after things are removed from the view?

Sohan http://smsohan.com skype:smsohan | gtalk:sohan39 | cell: 403-714-2673

On Mon, Nov 19, 2012 at 8:49 AM, Eonasdan [email protected] wrote:

I took everything out of the View I was using to be this:

You (hopefully) have requested a password reset for [..]. Please proceed to the password reset page or copy this link into your browser:

— Reply to this email directly or view it on GitHubhttps://github.com/smsohan/MvcMailer/issues/71#issuecomment-10518433.

smsohan avatar Nov 19 '12 15:11 smsohan

yup with the same error message

On Mon, Nov 19, 2012 at 10:53 AM, SM Sohan [email protected] wrote:

Is this still failing after things are removed from the view?

Sohan http://smsohan.com skype:smsohan | gtalk:sohan39 | cell: 403-714-2673

On Mon, Nov 19, 2012 at 8:49 AM, Eonasdan [email protected] wrote:

I took everything out of the View I was using to be this:

You (hopefully) have requested a password reset for [..]. Please proceed to the password reset page or copy this link into your browser:

— Reply to this email directly or view it on GitHub< https://github.com/smsohan/MvcMailer/issues/71#issuecomment-10518433>.

— Reply to this email directly or view it on GitHubhttps://github.com/smsohan/MvcMailer/issues/71#issuecomment-10518581.

Jonathan Peterson "Desiderio Domini" <><

Eonasdan avatar Nov 19 '12 15:11 Eonasdan

Can you try the example project to see if this is a problem with something specific to your project or MvcMailer in general? https://github.com/tylermercier/MvcApplication3

Sohan http://smsohan.com skype:smsohan | gtalk:sohan39 | cell: 403-714-2673

On Mon, Nov 19, 2012 at 8:54 AM, Eonasdan [email protected] wrote:

yup with the same error message

On Mon, Nov 19, 2012 at 10:53 AM, SM Sohan [email protected] wrote:

Is this still failing after things are removed from the view?

Sohan http://smsohan.com skype:smsohan | gtalk:sohan39 | cell: 403-714-2673

On Mon, Nov 19, 2012 at 8:49 AM, Eonasdan [email protected] wrote:

I took everything out of the View I was using to be this:

You (hopefully) have requested a password reset for [..]. Please proceed to the password reset page or copy this link into your browser:

— Reply to this email directly or view it on GitHub< https://github.com/smsohan/MvcMailer/issues/71#issuecomment-10518433>.

— Reply to this email directly or view it on GitHub< https://github.com/smsohan/MvcMailer/issues/71#issuecomment-10518581>.

Jonathan Peterson "Desiderio Domini" <><

— Reply to this email directly or view it on GitHubhttps://github.com/smsohan/MvcMailer/issues/71#issuecomment-10518663.

smsohan avatar Nov 19 '12 16:11 smsohan

I have the same problem.

ddokshin avatar Jun 11 '14 11:06 ddokshin