MvcMailer

Problem

A lot of people recommended that MvcMailer is a great package for those who want to send email from ASP.NET MVC app but seems like the author of that package really didn’t get time to update the dependencies of his package.

Here is what you will see when you try installing MvcMailer in VS 2010.

PM> Install-Package mvcmailer
Attempting to resolve dependency ‘T4Scaffolding (≥ 0.9.7)’.
Attempting to resolve dependency ‘EntityFramework (≥ 4.1.10311.0)’.
You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=224682. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed ‘EntityFramework 4.1.10715.0’.
Successfully installed ‘T4Scaffolding 0.9.9’.
Successfully installed ‘MvcMailer 1.1’.
Successfully removed ‘EntityFramework 4.1.10331.0’ from MvcApplication3.
Successfully added ‘EntityFramework 4.1.10715.0’ to MvcApplication3.
Successfully added ‘T4Scaffolding 0.9.9’ to MvcApplication3.
Set-DefaultScaffolder : Unable to cast object of type ‘NuGet.SemanticVersion’ to type ‘System.Version’.
At C:\users\michael.sync\documents\visual studio 2010\Projects\MvcApplication3\packages\T4Scaffolding.0.9.9\tools\install.ps1:22 char:22
+ Set-DefaultScaffolder <<<< -Name DbContext -Scaffolder T4Scaffolding.EFDbContext -SolutionWide -DoNotOverwriteExistingSetting
+ CategoryInfo : NotSpecified: (:) [Set-DefaultScaffolder], InvalidCastException
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Set-DefaultScaffolder : Unable to cast object of type ‘NuGet.SemanticVersion’ to type ‘System.Version’.
At C:\users\michael.sync\documents\visual studio 2010\Projects\MvcApplication3\packages\T4Scaffolding.0.9.9\tools\install.ps1:23 char:22
+ Set-DefaultScaffolder <<<< -Name Repository -Scaffolder T4Scaffolding.EFRepository -SolutionWide -DoNotOverwriteExistingSetting
+ CategoryInfo : NotSpecified: (:) [Set-DefaultScaffolder], InvalidCastException
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Set-DefaultScaffolder : Unable to cast object of type ‘NuGet.SemanticVersion’ to type ‘System.Version’.
At C:\users\michael.sync\documents\visual studio 2010\Projects\MvcApplication3\packages\T4Scaffolding.0.9.9\tools\install.ps1:24 char:22
+ Set-DefaultScaffolder <<<< -Name CustomTemplate -Scaffolder T4Scaffolding.CustomTemplate -SolutionWide -DoNotOverwriteExistingSetting
+ CategoryInfo : NotSpecified: (:) [Set-DefaultScaffolder], InvalidCastException
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Set-DefaultScaffolder : Unable to cast object of type ‘NuGet.SemanticVersion’ to type ‘System.Version’.
At C:\users\michael.sync\documents\visual studio 2010\Projects\MvcApplication3\packages\T4Scaffolding.0.9.9\tools\install.ps1:25 char:22
+ Set-DefaultScaffolder <<<< -Name CustomScaffolder -Scaffolder T4Scaffolding.CustomScaffolder -SolutionWide -DoNotOverwriteExistingSett
ing
+ CategoryInfo : NotSpecified: (:) [Set-DefaultScaffolder], InvalidCastException
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Successfully added ‘MvcMailer 1.1’ to MvcApplication3.
Set-DefaultScaffolder : Unable to cast object of type ‘NuGet.SemanticVersion’ to type ‘System.Version’.
At C:\users\michael.sync\documents\visual studio 2010\Projects\MvcApplication3\packages\MvcMailer.1.1\tools\Install.ps1:23 char:22
+ Set-DefaultScaffolder <<<< -Name Mailer -Scaffolder $mailerScaffolder -SolutionWide -DoNotOverwriteExistingSetting
+ CategoryInfo : NotSpecified: (:) [Set-DefaultScaffolder], InvalidCastException
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet
—————————READ ME—————————————————

Your default Mailer Scaffolder is set to Mailer.Razor

You can generate your Mailers and Views using the following Scaffolder Command

PM> Scaffold Mailer UserMailer Welcome,GoodBye

Edit the smtp configuration at web.config file before you send an email

You can find more at: https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide

————————————————————————————-
Successfully uninstalled ‘EntityFramework 4.1.10331.0’.

PM>

Solution

As you can see, MvcMailer has the dependency on “T4Scaffolding (v0.9.9)” package which has dependency on “EFCodeFirst” package which is the outdated version of EF. All you have to do to make MvcMailer works is very simple. Just update “T4Scaffolding” package by using “Update-Package” command from Nuget Console.

PM> Update-Package T4Scaffolding
Updating ‘T4Scaffolding’ from version ‘0.9.9’ to ‘1.0.6’ in project ‘MvcApplication3’.
Successfully removed ‘T4Scaffolding 0.9.9’ from MvcApplication3.
Successfully installed ‘T4Scaffolding 1.0.6’.

A different version of T4Scaffolding is already running in this instance of Visual Studio
Please restart Visual Studio to avoid unexpected behavior.
You won’t be able to use scaffolding until you restart Visual Studio.

Successfully added ‘T4Scaffolding 1.0.6’ to MvcApplication3.
Successfully uninstalled ‘T4Scaffolding 0.9.9’.

After updating the package, you need to restart the Visual Studio.

Testing

Now, you can test MvcMailer’s Scaffold by using the command below. If you want to know more details, you can read “MvcMaler: Step by Stp Guide“.

PM> Scaffold Mailer.Razor UserMailer Welcome,PasswordReset
Added MvcMailer output ‘Mailers\IUserMailer.cs’
Added MvcMailer output ‘Mailers\UserMailer.cs’
Added MyScaffolder output ‘Views\UserMailer\_Layout.cshtml’
Added MyScaffolder output ‘Views\UserMailer\Welcome.cshtml’
Added MyScaffolder output ‘Views\UserMailer\PasswordReset.cshtml’
PM>

One thought on “MvcMailer

Leave a Reply

Your email address will not be published. Required fields are marked *