Sending email in an MVC application

I have implemented emailing in some of the web application I have done in the past, and also one of the recent project. So I thought this could be helpful for some of the developers, so decided to share it.

The process could be divided into 3 simple activities.

  1. Create the partial view, with self contained CSS
  2. Implement a method which would generate a string object after initialising the partial view with its model
  3. Send the mail

Note: The below implementaion was done for a site hosted on GearHost

Here is the method converts the partial view to a string. This requires the reference to the Controller object, the partial view name, and Model object that is required by the view.

partial to string

After creating the view that you need, you can use the same code below to send the email.

emailing

Hope this helps. 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s