How To Send Email In ASP.NET MVC

4.49 (81 votes)

This article takes a comprehensive look at the business of generating and sending email from an ASP.NET MVC application. It covers the most common use cases as well as some advanced scenarios. It also explores some of the more common errors that arise from attempting to generate and send email programmatically from an ASP.NET MVC site.

First, I only cover creating emails to be sent via SMTP (Simple Mail Transfer Protocol) in this article. There are many other ways to send email - POP3, IMAP, Exchange Web Services, Outlook Interop and so on. None of those will be covered here. The .NET framework includes a library specifically for sending email via SMTP. It is found in the System.Net.Mail namespace, and includes the key classes that enable the creation of an email message, and passing it to an SMTP server for sending. Before you can do anything with them, you need access to an SMTP service. Your ISP may already provide you with access, but if not, you can easily get access via any number of free services such as Google's Gmail system, Microsoft's Outlook.com/Live service, one provided by Yahoo and so on.

Basic Email Sending

The most common use for email in a web setting is to enable visitors to provide feedback or make contact with the site owners via a form. The following steps will walk you through creating a new MVC 5 application, adding a view model and view, and then creating an action method to process a form submission to generate an email.

  1. Open Visual Studio and from the New Project link, or File » New » Project, create a new project. Select ASP.NET Web Application from the C# templates and click OK.

    MVC5 Email

  2. Choose MVC and click OK, leaving the other options as the are.

    MVC5 Email

  3. Add a new class file to the Models folder and name it EmailFormModel.cs. Replace the existing code with the following:

    using System.ComponentModel.DataAnnotations;
    
    namespace MVCEmail.Models
    {
        public class EmailFormModel
        {
            [Required, Display(Name="Your name")]
            public string FromName { get; set; }
            [Required, Display(Name = "Your email"), EmailAddress]
            public string FromEmail { get; set; }
            [Required]
            public string Message { get; set; }
        }
    }
  4. Locate the Contact.cshtml file in the Views\Home folder and replace the existing code with the following:

    @model MVCEmail.Models.EmailFormModel
    @{
        ViewBag.Title = "Contact";
    }
    <h2>@ViewBag.Title.</h2>
    
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
        <h4>Send your comments.</h4>
        <hr />
        <div class="form-group">
            @Html.LabelFor(m => m.FromName, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(m => m.FromName, new { @class = "form-control" })
                @Html.ValidationMessageFor(m => m.FromName)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.FromEmail, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(m => m.FromEmail, new { @class = "form-control" })
                @Html.ValidationMessageFor(m => m.FromEmail)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.Message, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextAreaFor(m => m.Message, new { @class = "form-control" })
                @Html.ValidationMessageFor(m => m.Message)
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" class="btn btn-default" value="Send" />
            </div>
        </div>
    }
    
    @section Scripts {
        @Scripts.Render("~/bundles/jqueryval")
    }
    
  5. Add these using directives to the top of the HomeController.cs file:

    using MVCEmail.Models;
    using System.Net;
    using System.Net.Mail;
  6. Add the following asynchronousContact method to the HomeController.cs file, replacing settings with valid values where indicated by comments:

    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Contact(EmailFormModel model)
    {
        if (ModelState.IsValid)
        {
            var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
            var message = new MailMessage();
            message.To.Add(new MailAddress("recipient@gmail.com"));  // replace with valid value 
            message.From = new MailAddress("sender@outlook.com");  // replace with valid value
            message.Subject = "Your email subject";
            message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message);
            message.IsBodyHtml = true;
    
            using (var smtp = new SmtpClient())
            {
                var credential = new NetworkCredential
                {
                    UserName = "user@outlook.com",  // replace with valid value
                    Password = "password"  // replace with valid value
                };
                smtp.Credentials = credential;
                smtp.Host = "smtp-mail.outlook.com";
                smtp.Port = 587;
                smtp.EnableSsl = true;
                await smtp.SendMailAsync(message);
                return RedirectToAction("Sent");
            }
        }
        return View(model);
    }
  7. Add the following ActionResult to HomeController.cs:

    public ActionResult Sent()
    {
        return View();
    }
  8. Navigate to Views\Home and add a new view called Sent.cshtml. Replace the content with the following:

    @{
        ViewBag.Title = "Sent";
    }
    <h2>Your message has been sent</h2>

You start by creating a MailMessage object. MailMessage is the class that represents an email to be sent. Recipients are represented as a collection of MailAddress objects. They are added to the To property of the MailAddress class. The sender is also represented as an instance of the MailAddress class and is assigned to the message's From property. The Subject and Body properties are self-explanatory. By default, email messages are created as plain text. If you want to send an HTML email, you pass HTML to the Body property (as in this example) and then explicitly set the IsBodyHtml property to true.

Once the message has been created, it needs sending. The SmtpClient class is responsible for that task. The configuration of the SmtpClient object is often the place where most email sending errors occur, so it is important to ensure that you use the right settings. They are almost identical for both Outlook and Gmail:

Gmail Outlook/Live
Host smtp.gmail.com smtp-mail.outlook.com
Port 587 587
EnableSsl true true
User Name Your email address Your email address
Password Your account password Your account password
     

You should check your provider's documentation for the correct values if you aren't using either of the services featured here.

Port 465 or 587?

Lots of code samples for Gmail feature port 465 but most people cannot get this to work. When they revert to port 587, their email suddenly works. According to Gmail's documentation SSL is required if you specify port 465. Many people think that setting EnableSsl to true achieves this, but in fact, it means that your app must be running under https. When you set EnableSsl to true, you actually switch TLS on, which is required for port 587. Https is not supported by the SmtpClient object. For more details, read the Remarks section of the docs on MSDN.

The user name and password are packaged up in an instance of the NetworkCredential class and passed to the Credentials property of the SmtpClient class. Then the mail is sent asynchronously using the SendMailAsync method.

Synchronous or Asynchronous?

The majority of code examples that illustrate using .NET libraries to send email will result in the email being sent synchronously via the SmptClient.Send() method. A web server has a limited number of threads available, and in high load situations all of the available threads might be in use. When that happens, the server can’t process new requests until the threads are freed up. With synchronous code, many threads may be tied up while they aren’t actually doing any work because they’re waiting for I/O (calls to external processes) to complete. With asynchronous code, when a process is waiting for I/O to complete, its thread is freed up for the server to use for processing other requests. As a result, asynchronous code enables server resources to be used more efficiently, and the server can handle more traffic with fewer delays.

In earlier versions of .NET, writing and testing asynchronous code was complex, error prone, and hard to debug. In .NET 4.5, writing, testing, and debugging asynchronous code is so much easier that you should generally write asynchronous code unless you have a reason not to. Asynchronous code does introduce a small amount of overhead, but for low traffic situations the performance hit is negligible, while for high traffic situations, the potential performance improvement is substantial.

Finally, you should be able to run the application by pressing F5, navigate to the Contact page and submit the form once you have provided some valid values.

Move settings to web.config

The code above is fine, but there is a potential problem. If you want to change the mail account that you are using, you need to make changes to source code. And that means a recompile and so on. Equally, if you want to send email from other parts of the application, you have to update the settings in multiple locations. One way to solve this problem is to move the settings into the web.config file. The system.net element includes a child element called mailSettings which is designed to support the storage of settings for sending email. the following block will go into the <configuration> section:

<system.net>
  <mailSettings>
    <smtp from="you@outlook.com">
      <network host="smtp-mail.outlook.com" 
               port="587" 
               userName="you@outlook.com"
               password="password" 
               enableSsl="true" />
    </smtp>
  </mailSettings>
</system.net>

Doing this reduces the amount of code you need to use in the Action method. Here's a revised version of the code you added earlier:

[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Contact(EmailFormModel model)
{
    if (ModelState.IsValid)
    {
        var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
        var message = new MailMessage();
        message.To.Add(new MailAddress("name@gmail.com")); //replace with valid value
        message.Subject = "Your email subject";
        message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message);
        message.IsBodyHtml = true;
        using (var smtp = new SmtpClient())
        {
            await smtp.SendMailAsync(message);
            return RedirectToAction("Sent");
        }
    }
    return View(model);
}

All of the SMTP configuration has been removed.

Sending to multiple recipients

If the email you want to send is intended for multiple recipients, you can add additional MailAddress objects to the To property of the MailMessage class:

message.To.Add(new MailAddress("one@gmail.com"));
message.To.Add(new MailAddress("two@gmail.com"));
message.To.Add(new MailAddress("three@gmail.com"));

If you don't want each recipient to see others in the recipient list, you can use the Bcc property and add recipients to that, just like with the To property:

message.Bcc.Add(new MailAddress("one@gmail.com"));
message.Bcc.Add(new MailAddress("two@gmail.com"));
message.Bcc.Add(new MailAddress("three@gmail.com"));

Adding Attachments

The MailMessage Attachments property provides the means to add attach multiple files to a mail message. Files can originate from one of two sources - either physical files stored in the file system, or as streams. If you want to attach a file from the file system, you pass the file path to the Attachment constructor:

message.Attachments.Add(new Attachment(HttpContext.Server.MapPath("~/App_Data/Test.docx")));

Attachments can be generated from stream objects. The two most common source of streams that represent files to be attached to email messages are uploaded files and files stored in a database in binary format. In the next section, you will amend the contact form to include a file upload control, and then attach the uploaded file to the email without saving it to the server.

Adding an upload as an attachment

  1. Alter the Contact view (Views\Home\Contact.cshtml) to include the changes highlighted in yellow:

    @model MVCEmail.Models.EmailFormModel
    @{
        ViewBag.Title = "Contact";
    }
    <h2>@ViewBag.Title.</h2>
    
    @using (Html.BeginForm("Contact", "Home", null, FormMethod.Post, new {enctype = "multipart/form-data"}))
    {
        @Html.AntiForgeryToken()
        <h4>Send your comments.</h4>
        <hr />
        <div class="form-group">
            @Html.LabelFor(m => m.FromName, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(m => m.FromName, new { @class = "form-control" })
                @Html.ValidationMessageFor(m => m.FromName)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.FromEmail, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextBoxFor(m => m.FromEmail, new { @class = "form-control" })
                @Html.ValidationMessageFor(m => m.FromEmail)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.Message, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                @Html.TextAreaFor(m => m.Message, new { @class = "form-control" })
                @Html.ValidationMessageFor(m => m.Message)
            </div>
        </div>
        <div class="form-group">
            @Html.LabelFor(m => m.Upload, new { @class = "col-md-2 control-label" })
            <div class="col-md-10">
                <input type="file" name="upload" />
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" class="btn btn-default" value="Send" />
            </div>
        </div>
    }
    
    @section Scripts {
        @Scripts.Render("~/bundles/jqueryval")
    }
    
  2. Alter the EmailFormModel to incorporate the highlighted line:

    using System.ComponentModel.DataAnnotations;
    using System.Web;
    namespace MVCEmail.Models
    {
        public class EmailFormModel
        {
            [Required, Display(Name="Your name")]
            public string FromName { get; set; }
            [Required, Display(Name = "Your email"), EmailAddress]
            public string FromEmail { get; set; }
            [Required]
            public string Message { get; set; }
            public HttpPostedFileBase Upload { get; set; }
        }
    }
  3. Add the highlighted code to the HttpPost Contact action method in the HomeController

    [HttpPost]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Contact(EmailFormModel model)
    {
        if (ModelState.IsValid)
        {
            var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>";
            var message = new MailMessage();
            message.To.Add(new MailAddress("name@gmail.com")); //replace with valid value
            message.Subject = "Your email subject";
            message.Body = string.Format(body, model.FromName, model.FromEmail, model.Message);
            message.IsBodyHtml = true;
            if (model.Upload != null && model.Upload.ContentLength > 0)
            {
                message.Attachments.Add(new Attachment(model.Upload.InputStream, Path.GetFileName(model.Upload.FileName)));
            }
            using (var smtp = new SmtpClient())
            {
                await smtp.SendMailAsync(message);
                return RedirectToAction("Sent");
            }
        }
        return View(model);
    }
  4. Build the application and run it (F5). Navigate to the Contact page and upload a file. The email with the uploaded file attached should be generated.

    The code that you added to the view provides a file upload control and sets the enctype of the form to multipart/form-data, which is an essential prerequisite to getting files uploaded to the server. You also added an additional property the the view model to cater for the uploaded file. The property is a HttpPostedFileBase type, which is a class that represents an uploaded file in .NET. In the controller, you check to see if the new property has any value at all before checking its ContentLength to see if the uploaded file has any data. If it does, your code passes its InputStream property to the Attachment constructor together with the name of the file.

Add attachment from a database

If you store files in a database table, they will be stored as a byte array. You need to convert this to a stream in order to be able to use the Attachment constructor that accepts a stream. In a previous article, I show how to store file content in a database using the Entity Framework. The article features a File entity, with a Content property representing the stored bytes. The following code demonstrates how to retrieve the content for a specific file, convert it to a stream and then create an attachment for your email:

public ActionResult Index(int id)
{
    var file = db.Files.Find(id);
    Attachment attachment;
    using (var stream = new MemoryStream())
    {
        stream.Write(file.Content, 0, file.Content.Length - 1);
        attachment = new Attachment(stream, file.FileName);
    }
    var message = new MailMessage();
    message.Attachments.Add(attachment);

    // etc...
}

Test Configuration

Sometimes you don't want to use an external mail provider when you are just testing your application. But you still need to know that email has been successfully generated. There are SMTP servers available for test purposes, but a simpler approach is to use the SpecifiedPickupDirectory option for the deliveryMethod property. This can be any folder on your system. It's simply a directory where email messages are placed as .eml files when your application generates them. You can specify that this is used in the web.config file:

<system.net>
  <mailSettings>
    <smtp deliveryMethod="SpecifiedPickupDirectory">
      <specifiedPickupDirectory pickupDirectoryLocation="C:\MailDump"/>
    </smtp>
  </mailSettings>
</system.net>

Common Email Sending Errors

The most common problem faced by people sending email from ASP.NET results from getting the SMTP configuration wrong. Usually this happens when people copy and paste code from blog posts without trying to understand it or checking that it does what it is supposed to. The configuration details I have provided for Gmail and Outlook.com are correct at the time this article was published, but that doesn't mean they won't change at some time. You should always check your email provider's documentation.

5.5.1 Authentication Required

This error can arise if you have not authorised your application. Both Gmail and Outlook detect where SMTP connections are coming from, and if you are using a new machine for the first time, you need to confirm that the attempt to send mail programmatically originated from you. Gmail send you an email with instructions on how to do this or display a message at the top of your web-based inbox about potential suspicious activity.

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first

Usually arises because you have not set EnableSsl to true but your email provider requires you to use TLS. Set the value to true and try again.

Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated

Your user name and/or password is incorrect, or you have specified true for defaultCredentials (web.config or UseDefaultCredentials if setting the SmtpClient object property), which will result in the credentials for the currently logged in user being used to authenticate against the mail server.

Summary

This article covered the basics of sending email from and ASP.NET MVC site. It also looked at how to add attachments from a number of sources. Finally, it covers the most common error messages encountered when sending email programmatically.

You might also like...

Date Posted:
Last Updated:
Posted by:
Total Views to date: 186935

49 Comments

- Afzaal Ahmad Zeeshan

A great way to teach the MVC framework for sending the emails... Also, what I found helpful was the async model explanation.

Off-topic, apart of these two methods, classes can also be used to store the data about SMTP client, and methods or members can be used to send emails from different part of the application. But, that won't be necessary as an example (tutorial) here.

- Satyabrata Mohapatra

Great article. Simple and up to the point.

- Plácido Bisneto

Please god. Just don't.
Don't do that.
Just use Postal.

http://aboutcode.net/postal/

- Mike

@Plácido,

It's a nice library. There are a couple of other similar ones out there. But there's nothing wrong with using System.Net.Mail if that's all you need. And the point of this article was to show how to use System.Net.Mail.

- Mike W

Does the EmailFormModel.cs model class map to db tables (ie: is add-migration needed) or is it a temporary holding area for the data? If it's temporary is the data removed from memory as soon as the message is sent?

Great article, thank you for posting!

~Mike

- Mike

@Mike W

The EmailFormModel is a class designed purely as a container for the data required by the view. It is referred to as a viewmodel. As such, it could be described as a temporary holding area for the data. It (along with any other objects instantiated as part of processing the request) will be disposed of once the request has been executed and the response sent to the browser.

- Vijay

Thanks

- Alistair

Hi Mike,
Just wanted to say a big thank you to you! You couldn't have made it simpler - worked first time for me. So pleased you took the time to put it out there its going to help a lot of people out!
: )

- Nelson

Hi, thank you so much for this tutorial but it shows me this message: Error 1: Can not find the type or namespace name 'Task' (are you missing a using directive or an assembly reference?)
C:\Users\Nelson\Documents\Visual Studio 2013\Projects\mymvc\mymvc\Controllers\HomeController.cs
How could i fix that error?

- Mike

@Nelson,

You need to include
using System.Threading.Tasks;
at the top of your controller code file.

- deepan

Your article is very very useful for me...thanks for giving this article ...this is very simple to learn....if u have any official website ,pls tell me ur official website...we r eagerly waiting for ur another article......thanks

- Hamid Mosalla

Thank you so much, very nice and thorough.

- John Noble

Excellent. Just what I was looking for. Either I am missing something or a small section is missing instructing to add a Sent.cshtml to the Views/Home folder? This line throws an error in the controller action:
return RedirectToAction("Sent");

Thanks!

- Ted Driver

Thanks for the great example Mike! I noticed in my implementation of your code that if I put some HTML in the message box, I get an HttpRequestValidationException from my site prior to my getting access to the model in the controller. I'm trying to work out where I would add a check for this prior to the runtime excepting. Any pointers on this?

- Emma

As mentioned by John Noble, there seems to be something missing in regards to:
return RedirectToAction("Sent");

- Mike

@John and Emma,

I have added the steps to describe how to include the Sent view. Thanks for your feedback.

- Mike

@Ted,

You need to add global error handling to your app. Something like what's described in this Stackoverflow thread

- surineni

perfect Mike, thanks for sharing such an easy way to initiate an email generation and I have a query , is it always mandatory to provide from details i.e to include (username, password, from email for the smtpclient object)

- Mike

@surineni,

Your email message requires a from address. If you need to authenticate with your SMTP server, you will need to pass it some credentials.

- Ronda P

Good article, from MVC I am attaching a PDF and emailing. I could not get this to work unless I first saved to the server, so that I don't have a lot of random files I am doing an await on my smtp.sendmailasynch and then trying a file.delete ... I am throwing an error that the process can not access the file as it is being used by another process. Any tips on what I missed?

- Mike

@Ronda,

It depends on how you are generating your PDF, but you should be able to use iTextSharp to create one as a stream and use that for an email attachment. See How do I create an attachment from a stream?

- Angel Garcia

finally got a way for this to access my account but the email i receive says that someone tried to access my account from an unsafe app. how can i make this a safe code?

- salman

thanks ...

- Steve

Hi Mike,
I found your article to be a paragon of clarity and described almost exactly my requirements. I am using MVC 5.2.
Imagine my frustration when I kept getting the dreaded "Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated", despite checking the credentials.
I am using an @outlook.com email address and have concluded that it is not enabled for SMTP. However, I cannot find anything in Outlook settings to enable SMTP. I am using a standard (free) outlook account.
Do you have any ideas?
Thanks.

- Mike

@Steve,

The example I featured used Outlookcom. I provide the settings you need to apply in the article. If you are still having issues, you should post a question to forums.asp.net.

- Dave

First, amazing article Mike. Thank you. I am able to send emails locally, but when trying after publishing on a subdomain for testing, I get this error message: Exception Details: System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 65.55.176.126:587

Have you ran across this with your implementations at all?

Thanks In Advance,

Dave

- Mike

@Dave,

Nope. But I would start by checking server firewalls.

- Juanis

Great example. I was looking for a simple way to do that and it helped me a lot. Thanks

- Gunasekhar

Good example. It will help a lot to me

- Catto

Stellar post on ASP.NET MVC sending an email. Really well written and enjoyed the ASync paragraph too. I spend a few hours reading & coding this; now I really understand it. This really helped me; I appreciate you writing this.
Thx 4 the info;
Catto

- Bob Macleod

I'm trying to get this into razor with vb. The part that none of the converters seem to handle is this:

@Html.LabelFor(m => m.FromName, new { @class = "col-md-2 control-label" })

What I get out of the converters is:

@Html.LabelForFunction(m) m.FromName, New With {Key .[class] = "col-md-2 control-label"})

But then I get the error:
Late binding operations cannot be converted to an expression tree.
(The error is on "m.FromName".)

I think this bit is the problem:
New With {Key .[class] = "whatever"}

I am new to inline Llambda, and new to Razor. Any suggestions? (besides switch over to c# :-)

- Mike

@Bob,

I think you want
@Html.LabelFor(Function(m) m.FromName, New With {.Class = "col-md-2 control-label"})

- Roberto Mateos

Hi Mike,

First of all say that the article is a great one, very clear and complete! Good job!
I have a list of emails in a SQL database, the challenge I face is that the possibility of having incorrect emails exists.
How your code will deal with that? Or what will you do/add to identify the incorrect emails? Catch the exceptions and create a log file with all the failures?
Thanks in advance :)

- Emil

Hello, first of all - thanks for such nice walkthrough how to send emails from MVC application. It was very helpful. I do have one additional question - how to send emails, which will appear for example in outlook.com under same thread ( or conversation ) ?

- Mike

@Emil,

That's not something you can influence though code. It is entirely a feature of Outlook.

- makhlas

hello,
thanks for sharing these tutos , but when i apply the send button, i'm gettin this error (Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated)

- Mike

@makhlas,

Try reading the Common Email Sending Errors section at the end of the article.

- Rex

This article was amazingly well written and covered almost every aspect of potential issues. I did encounter the Authentication 5.5.1 error. Thank you!

- Lotus

Hi,
I have issue with having multiple addresses added in the MailMessage. Even if one address is incorrect or invalid for any reason (say its domain is wrong), what is the best way to capture the exception and log the list of email addresses that the email didn't get sent to. I am using smtp client to send email from ASP.Net Web api (C#). Any help is greatly appreciated.

- Zahid

Hello Sir,

Great post. Just a quick question, is it possible if we can ask a client to save his/her pop/smtp details in an application and we can use that detail to send email? Lets say in a portal application where a contact form is submitted and we want to send a thank you email from the client's email credentials.

Thanks,

- Mike

@Zahid,

Yes, you could do that but it is not very practical. If someone wants to send an email from their own account, they don't need to use someone else's web site for that. Also, you are likely to run into the issue of having to validate your application with Google or Live or Outlook.com every time you use someone else's mail settings.

- Mel

Hi Mike,

Great articles, can't wait to try this tonight at home.

My hosting service provider has told me to use CDOsys to email, something to do with being hosted on a window server. Is this very different to the method you describe above in your article.

- stijn

Hey, i keep getting an http 404 error while i copied almost exact the same pages. I think it has something to do with my HTTP POST in my controller....Do you have any suggestions how i can solve this?
Thanks

- Mike

@Mel

CDOSys is an old COM-based mailing component that was used by classic ASP applications and very early versions of ASP.NET (pre 2005). Your hosting provider doesn't know what they are talking about - unless you are using classic ASP (page files end in .asp).

- Mel

Thanks Mike,

Have made the changes to my app, as per your document. Will upload the changes tonight, and test, and let you know.

thanks

- Regin

Thanks Mike! Your articles are very easy to follow and comprehensive at the same time.

- preeti

Hi Mike, firstly thank you for the article. It was a great help for a novice like me.. I tried duplicating your example .. but comes up with 404 error when the Contact view is run .. says " The Resource cannot be found " .. (No errors) .. Do you have any suggestions how i can solve this?

- preeti

Hey Mike, I mailed you for the 404 error .. I think it is because of the Contact Action, we are saying that "EmailFormModel object is expected " and we are not passing it during the initial page load that view comes out as unavailable... Do you have any suggestions to avoid this ? Thank u ..

- Tom

Absolutely fantastic walkthrough - covered everything. I was looking for a good example of async smtp sending and this was more than perfect (if that's possible)!

Recent Comments

Pam 30/08/2017 11:30
In response to Sending Email in Razor Pages
Mike, RazorPages sound like a nice choice for somebody still working in ASP classic who wants to to...

Robby Robson 15/08/2017 00:43
In response to Routing in Razor Pages
Mike: great stuff. Now that .Core Standard 2.0 is formally out, how soon will you rewrite your book...

Satyabrata Mohapatra 28/07/2017 08:59
In response to Sending Email in Razor Pages
Bit off topic, but congratulation sir for your MVP award. You deserve it !!!...

Satyabrata Mohapatra 23/07/2017 16:43
In response to Razor Pages - The Elevator Pitch
@Dale Severin You can continue to build apps using asp.net web pages....

Satyabrata Mohapatra 23/07/2017 16:40
In response to Sending Email in Razor Pages
Thanks for sharing...learned a lot...

Gfw 22/07/2017 11:53
In response to Sending Email in Razor Pages
Question... Does System.Net.Mail support SSL?...

Dale Severin 20/07/2017 03:38
In response to Razor Pages - The Elevator Pitch
I work with razor web pages extensively. I appreciate the rapid development it permits me to I am as...

Obinna Okafor 14/07/2017 01:19
In response to Routing in Razor Pages
Thank you, Mike. Good post....

Satyabrata Mohapatra 11/07/2017 16:02
In response to Routing in Razor Pages
Very powerful routing system!!...

Cyrus 05/07/2017 03:41
In response to Razor Pages - Getting Started With The Preview
How can I trim packages and services as much as possible to use just razor pages? I don’t want to to...