Create email C# with Asp.Net

I am using Visual Studio 2013 for Web to develop an Asp.Net page with C#.
Now, I am in the moment to create a web form where the user clicks a button and an outlook message is displayed with certain information he currently have in the page, then the user should click on 'Send'.

First of all, the code displays an error in the 'Outlook.MailItem mailItem = (Outlook.MailItem)' suggesting there is no 'using Microsoft.Office.Interop.Outlook'

The code I am trying to make work is the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Office.Interop.Outlook;

namespace WebApplication7
    public partial class _Default : Page
        protected void Page_Load(object sender, EventArgs e)


        protected void Button1_Click(object sender, EventArgs e)

        private void CreateMailItem()
            Outlook.MailItem mailItem = (Outlook.MailItem)
            mailItem.Subject = "This is the subject";
            mailItem.To = "";
            mailItem.Body = "This is the message.";
            mailItem.Importance = Outlook.OlImportance.olImportanceLow;


Open in new window

José PerezAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Miguel OzConnect With a Mentor Software EngineerCommented:
Please check this link:
It is a bit dated, but MailMessage and SmtpClient  are the standard way to send emails in .NET. The info is very comprehensive and it provides a sample email form page.
Notice that you can put your SMPT server details in your configuration file as described on the link.
This is server side code, it would execute on the server hosting the website and not the current users PC.  Since outlook 2000 service pack 2 creating an email is restricted, you might want to look into outlook redemption as a workaround.
käµfm³d 👽Commented:
You could use a mailto link in your page; however, keep in mind that you are very limited in what you can populate via the mailto link. A mailto link will typically result in the user's default email application being opened. If you go this route, then because a mailto is itself a link, you will have to URL-encode the data to ensure special characters--like newlines, spaces, tabs, etc.--are handled correctly.
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

José PerezAuthor Commented:
mmm interesting, do you have an example of how to generate emails with C# or code?
José PerezAuthor Commented:
I found sample code for mailto but the bad part is that it depends on the mail client the user have. Also, it is not very recommended, so none of the solutions provided work for us.

I was recommended to use an asp-c# contact form... does anyone of you have a sample page to do it? (VS2012-VS2013)

käµfm³d 👽Commented:
In a web environment, MailMessage and SmtpClient will not let you show the mail on the user's screen, nor will it provide them with a send button, nor will it go through the user's Outlook. You could code custom pages/views that accomplish the first two, but not the last one. AFAIK, the mailto link is the only way to get all 3, but it is limited. MailMessage and SmtpClient run on the server, not the client.
All Courses

From novice to tech pro — start learning today.