Create email C# with Asp.Net

Posted on 2014-12-16
Medium Priority
Last Modified: 2014-12-26
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 = "someone@example.com";
            mailItem.Body = "This is the message.";
            mailItem.Importance = Outlook.OlImportance.olImportanceLow;


Open in new window

Question by:José Perez
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Expert Comment

ID: 40504603
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.
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40505250
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.

Author Comment

by:José Perez
ID: 40505512
mmm interesting, do you have an example of how to generate emails with C# or asp.net code?

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

by:José Perez
ID: 40506055
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)

LVL 36

Accepted Solution

Miguel Oz earned 1500 total points
ID: 40510360
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.
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40510456
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.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question