andrewdavey / postal

Email sending for asp.net mvc using the view engine system to render emails.
http://aboutcode.net/postal
MIT License
536 stars 168 forks source link

Embedding images "Object reference not set to an instance of an object" #58

Closed p10tyr closed 10 years ago

p10tyr commented 10 years ago

Following the example using version 0.8.2.0 I get Object reference not set to an instance of an object. I dragged the image onto the view so spelling is correct and the url looks the same like your example. Also i tried without the tilde and without slashes.

Happening during local VS debugging.

image

The view

image

Running a out of BOX MVC4 Site with Razor. Nothing fancy on the controllers or on routing.

tbasallo commented 10 years ago

Same here. The issue is that the imageembedder is not added when there isn't an alternate view because CreateAlternativeView is never called. At least that what I got from 30 minutes of debugging. If you create an alternate view (text and html per the instructions) you can get it to work.

I tried adding the embedder to the email when initializing the Email() but it doesn't work.

As a fix:

ImageEmbedder is only called once, EmailParser line 129.

        var imageEmbedder = new ImageEmbedder();
        email.ViewData["Postal.ImageEmbedder"] = imageEmbedder;

I need to look and see where and when it would make sense to embed it a simple view. If I can get to this I'll do a PR to get it in.

tbasallo commented 10 years ago

Just as a follow up, until this is fixed, you can do the following to get it to run. It only requires an extra file, assuming Template.cshtml is your file:

Template.cshtml: Views: html Template.Html.cshtml: Your actual template with the Embed helper

andrewdavey commented 10 years ago

Fixed in v1.1.0