Comments (9)
I have also spent some hours trying to get around this issue.
Mine solution was as follows (pseudo C# code):
Attachment someImageAttachment = new Attachment(imagePath);
emailModel.SomeImageContentId = someImageAttachment.ContentId;
email.Attach(someImageAttachment);
in Email.cshtml:
<img src="cid:@Model.SomeImageContentId" alt="SomeImage" />
Works perfectly in every e-mail client I have tested and the image is not visible as an attachment, which makes this solution even more awesome ;)
Hope it helps you and saves you lots of time :)
from postal.
I hate to simply say "Me too" but I have exactly the same problem.
from postal.
I've been looking into this. and isn't anything to do with postal. The fact is that RazorEngine (upon which postal relies) has no notion of the HtmlHelper which all the extension methods hang off of. When it renders a template, the template inherits from an base class provided by RazorEngine which does not have a Html member.
The workaround is to simply create an new class that inherits from Postal.Email and then implement your helpers on it or as extension methods to it.
from postal.
Actually, this sounds like the same problem I had when trying to create database driven views. I managed to work it out though - it is because when compiling the view outside of the context of the Views folder, the main Web.config is used (as opposed to the one in the Views folder) and the namespaces required for the @html and other objects are not included in the main Web.config.
To fix the problem, you need to add the following config sections to your ROOT web.config:
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
</configSections>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="true" />
</appSettings>
See this link for more details if you need them: http://forums.asp.net/t/1705855.aspx/1
from postal.
@JerryDoubleU Thank you! This worked for me :)
from postal.
@JerryDoubleU Wow, that is a nice workaround!
from postal.
@JerryDoubleU that worked fine. Awesome workaround! Thanks!
from postal.
@JerryDoubleU Thanks for posting!
from postal.
@JerryDoubleU Thanks, is Work ...
have also spent some hours trying to get around this issue.
Mine solution was as follows (pseudo C# code):
Attachment someImageAttachment = new Attachment(imagePath);
emailModel.SomeImageContentId = someImageAttachment.ContentId;
email.Attach(someImageAttachment);
Works perfectly in every e-mail client I have tested and the image is not visible as an attachment, which makes this solution even more awesome ;)
Hope it helps you and saves you lots of time :)
from postal.
Related Issues (20)
- Add support on other html attributes except alt in @Html.EmbedImage() HOT 2
- How to add external link with params? HOT 2
- Is this project still being supported? HOT 3
- How to identify if the email is sent or not HOT 3
- Html Helpers not working from console application HOT 4
- Postal MVC5 project references MVC 5.1.0.0 instead of 5.1.2 as the requirements state HOT 5
- Postal w/o MVC NuGet package?
- How to provide smtp settings runtime(not in web or app config)
- With Framework 4.6.2 it give error Attempted to access an element as a type incompatible with the array HOT 4
- Previewing emails with addresses with names HOT 3
- Install-Package : Input string was not in a correct format. HOT 5
- Continuation of Postal HOT 26
- enable sasl authentification HOT 7
- System.ArgumentNullException with .NET 4.5.2 WebApi HOT 9
- Sample For Postal.AspnetCore? HOT 3
- The parameter 'addresses' cannot be an empty string. HOT 1
- Layouts Stopped Working
- MVC4 throws exception when using autofac and MVC async controller actions
- How to use Postal with Unity IoC Container MVC 5?
- Subject encoding HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from postal.