Nuget Goodness

MVC Confirmation Email – Nuget

by Kevin on October 8, 2011



I’ve received several requests to update my original post dealing with adding a confirmation step to the standard ASP.NET MVC registration process so that it can work with ASP.NET MVC3. This seemed like a perfect place to use (and learn) Nuget, so you don’t have to deal with all the steps of creating the methods, modifying the views, etc.


For now, I’m going to assume that you already have Nuget installed and you have some idea of how to use it. If you don’t, read through the instructions at the Nuget site, or check out blog posts by Scott Hanselman or Phil Haack. If you still need help, post something in the comments and I’ll expand this post to include a Getting Started section.

Step 1a – Create a New Project

In Visual Studio, create a new ASP.NET MVC 3 Internet Application.


Step 1b – Work with an Existing Project

This will work with an existing project, but I’m assuming that you’re using default everything. If you’ve modified the AccountController or AccountModels in an uber custom way, you’ll likely experience pain. If you’re using out-of-the-box functionality, you won’t have any issues. And by “won’t”, I mean you’re completely on your own.

Step 2 – A little preparation

Now that you got your project, rename Controllers/AccountController.cs and Views/Account/LogOn.cshtml by adding “.old” to each file.


This needs to be done because Nuget cannot modify existing files (or at least I don’t know how to do it). These files are included in the Nuget package, and the default behavior of Nuget is to ignore any files that it finds on disk that match files in the package. By renaming them, if you have any custom code in there, you won’t lose it – you’ll just need to port it over to the new files.

Step 3 – Installing the package

A. From the console:

If you’re a fan of the console, Select Tools | Library Package Manager | Package Manager Console. At the console prompt type: install-package MvcConfirmationEmail. Nuget will download the package and modify your project accordingly.


B. From the User Interface:

Right-click on your project root, and select “Manage Nuget Packages…”. When the dialog window pops-up, enter “ConfirmationEmail” (one word) in the search text box in the upper right corner.


After a few seconds, it will find the MvcConfirmationEmail package (shown above). Click the install button, and it will download and install the package into your project.


If you didn’t rename the files as noted in Step 2 – this won’t work, and you will need to uninstall the package (PM>uninstall-package MvcConfirmationEmail), rename the files, and do this again.

Step 4 – Update web.config

When Nuget installed the package, a few additions were made to web.config so that you can configure your email service provider’s settings.

A. Email From Name

When you send an email to someone during the registration process, it has to come from a named account. Open up web.config and find the configuration\appSettings section. There is a key named MvcConfirmationEmailFromAccount. Change the value to the account name that will be sending the email. I’ve been using Gmail as my test account and it works great.

B.  Mail Settings

You need to configure the settings for your email service provider. Head down to the bottom of the config file, and you’ll find the\mailSettings\smtp node. Set the appropriate values for host, userName, password, and port, Gmail requires port 587 for SMTP – if you’re not using Gmail – you will need to check with your service provider to see what this should be.

That’s it! You should now be able to run the application and have the same functionality/workflow available in the original post. If you run into any problems or have any questions, please post down in the comments section and I’ll be happy to walk through your issues.

UPDATE 10/18/2011: I created a sample site on AppHarbor that you can use to test the functionality/workflow.

{ 19 comments… read them below or add one }

jc October 13, 2011 at 7:07 pm

This was exactly what I was looking for:
Everything is working for me except when I click on the confirmation link in the perspective users recieved email, it returns in the browser as “could not connect to″.

As I am hosting on AppHarbor, could this may be the reason? Any pointers would be very much appreciated.
Many thanks for the turtorial Jc


Kevin October 17, 2011 at 9:46 am

JC -

Hmmm… I haven’t tried this with appharbor yet, but it should work. If you’d like I could send you an email and we could do more troubleshooting off-line.




jc October 17, 2011 at 1:38 pm

Hi Kevin,

Yes please, that would be terrific :)

Thank you v. much


Kevin October 18, 2011 at 8:09 am

JC –

I just created a test app on appharbor and I got the same error. When the confirmation url is built, it includes a port number… so the confirmation link I received was “”. When I removed the port number I ended up with – and that WORKED. I need to look at the code that’s building the url and make sure it’s not including the port.

For now, you can got into the SendConfirmationEmail method and change the line:
string verifyUrl = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + “/account/verify?ID=” + confirmationGuid;


string verifyUrl = “” + “/account/verify?ID=” + confirmationGuid;

WHERE: “” is the name of your appharbor application. Mine would be “”.

This isn’t ideal (as it won’t work locally)… and I’ll dig into it more tonight.




Kevin October 18, 2011 at 11:37 pm

JC –

Based on this support note on AppHarbor I just upgraded the package to v1.1. You can either create a new project and run ‘Install-Package MvcConfirmationEmail’ – or run ‘Update-Package MvcConfirmationEmail’ in a v1.0 project. Thank you for pointing this out! I tested that it works locally, as well as when deployed to AppHarbor. Please let me know if you have any questions.



jc October 19, 2011 at 6:51 pm

Hi Kevin,

You are a star. I simply updated to 1.1 and bobs your uncle.

Brilliant brilliant brilliant. I would have never figured that out.

Thanks again JC


James Burton November 7, 2011 at 12:46 pm

One approach that I’m trying out that could be useful for you is to implement AccountController as a partial class, then you only need to add the partial keyword and remove excess methods from the existing controller, whilst including the controller methods for this as AccountController.MvcConfirmation.cs.pp (NB: use the substitutions to match the namespace) instead of calling it AccountController.cs.


ProgTick November 29, 2011 at 12:47 am

Is this nuget still there? It didn’t come up in my search.


Kevin November 29, 2011 at 12:58 am

ProgTick -

It’s there… if you go to the Nuget Package Manager Console, you can type in “PM> Install-Package MvcConfirmationEmail” (minus the quotes). The search on is not very good – but it’s there…

I updated the tags on the package… so you should now search for ConfirmationEmail (no spaces)… and their indexing will find it better. Thanks for finding this issue!




Yung March 19, 2012 at 10:10 pm

I tried to register myself on your test app and I just get the following msg,
“Sorry, an error occurred while processing your request.”
I also did not receive a confirmation email. Do you have any idea what’s going on?



Kevin March 19, 2012 at 11:10 pm

Hi Yung -

Sorry about that! My password had expired… so I created a new gmail account and reset the credentials. I just tested it and it’s working now. I deleted your email address from the server so you should be able to retry it now. I guess I should pay more attention to this :).




Vincenz May 21, 2012 at 9:30 am

Hi Kevin,

I’m using your approach with MVC 4 Beta and I got a bad problem. When I register with my app the confirmation email is sent and all is working well. When I register a new user with the same email address theconfirmation mail isn’t sent at all, eventhough it passes the client.Send(message) in debug without any errors. Why am I not able to test the functionality twice with the same email address?




Vincenz May 21, 2012 at 9:43 am

Well, thats embarrassing, it was all my junk email folder. :D


Kevin May 21, 2012 at 5:37 pm

Hi Vincenz – been there, done that! Glad you’ve got it working. Any issues with MVC4?


Steve June 24, 2012 at 1:15 pm

This worked out really well. Thanks! Now I’m trying to add the ChangePassword behavior. I’m still learning this, so I’ll bang my head on it a while, but if anyone wants to post their solution, I’d appreciate it.


Steve June 24, 2012 at 7:07 pm

Where is the phrase “Thank you for registering. Please check your email for a confirmation message with a link that will confirm your account. Once you click the link, your registration will be complete.” buried in the code? Has to be obvious but I can’t find it.


John V July 25, 2013 at 11:24 am

I’d like to use this in an MVC4 project, but it appears the AccountController is set up much differently by default. I could probably sort out the differences, but I was looking for something that would save me some time.

Any chance you’ve done an MVC4 version and I just haven’t found it yet?


Olsman January 12, 2014 at 1:49 pm

Hello Kevin,

I tried a couple of different approaches to implement your NUget code into the “default” MVC4 project in Visual Studio 2013. Unfortunatelly I was not able to get the code working, I have to impression that quite a few things have been changed in the “default” template. The is for instance no “LogOn.cshtml” available instead there is a “Login.cshtml”. Also there is no ChangePasswordModel. By default I get 5 error messages, in short on ChangePasswordModel, LogOnModel, RegisterModel, unassigned local variables changePasswordSucceeded and creatStatus. At this moment too many errors for me to handle, so my question to you is, could you have a look at this? Am I doing things wrong or should your code be modified in order to use it in the new version of MVC(4)? I also downloaded your project made in VS2012, which also gives an error compiling it to VS2013.


Kevin January 12, 2014 at 3:33 pm

Hi Olsman – take a look at this… it looks like this has been updated for MVC4 – I’ll take a deeper look tonight.


Leave a Comment

{ 1 trackback }

Previous post: