title: Send Email from an Asp.Net Webform Application using Microsoft Outlook
body: <p>I have an<code>asp.net</code> web form which on click of a button sends i want an email to be sent to my Microsoft outlook email account. I have done this on other </p>
  
  <p>websites but that was using hotmail but all external web email providers are blocked by the companies firewall (as i tried setting up a gmail account) so </p>
  
  <p>i need to use Outlook but i have not idea on how to implent this and solutions i have seen on Google dont seem to work. I dont know if it'll make a </p>
  
  <p>difference or not but i have been informed that the users password epxires every 30days so i suspect i'll need to use windows authenication or something </p>
  
  <p>but not sure.</p>
  
  <p>I'm not sure on how Outlook send the email as i know from past experience from using hotmail that the email is just sent on click of the button but i'm </p>
  
  <p>not sure if outlook would open the email window for the user to click the send button. If it does, i need the information captured on the webform to be </p>
  
  <p>containd in the email and the content of the email body not to be altered (if this can be done, again not ot sure if it can but not a problem if it </p>
  
  <p>can't).</p>
  
  <p>Below is the code i used for when i tried gmail but as i said i was told it wouldnt be allowed.</p>
  
  <pre><code>using System.Configuration;
  using System.Net.Mail;
  using System.Net;
  using System.IO;
  
  protected void BtnSuggestPlace_Click(object sender, EventArgs e)
          {
              #region Email
              try
              {
                  //Creates the email object to be sent
                  MailMessage msg = new MailMessage();
  
                  //Adds your email address to the recipients
                  msg.To.Add("MyEmailAddress@Test.co.uk");
  
                  //Configures the address you are sending the email from
                  MailAddress address = new MailAddress("EmailAddress@Test.com");
                  msg.From = address;
  
                  //Allows HTML to be used when setting up the email body
                  msg.IsBodyHtml = true;
  
                  //Email subjects title
                  msg.Subject = "Place Suggestion";
  
                  msg.Body = "&lt;b&gt;" + lblPlace.Text + "&lt;/b&gt;" + "&amp;nbsp;" + fldPlace.Text
                             + Environment.NewLine.ToString() +
                             "&lt;b&gt;" + lblLocation.Text + "&lt;/b&gt;" + "&amp;nbsp;" + fldLocation.Text
                             + Environment.NewLine.ToString() +
                             "&lt;b&gt;" + lblName.Text + "&lt;/b&gt;" + "&amp;nbsp;" + fldName.Text;
  
                  //Configures the SmtpClient to send the mail
                  SmtpClient client = new SmtpClient("smtp.gmail.com");
                  client.EnableSsl = true; //only enable this if the provider requires it
  
                  //Setup credentials to login to the sender email address ("UserName", "Password")
                  NetworkCredential credentials = new NetworkCredential("MyEmailAddress@Test.co.uk", "MyPassword");
                  client.Credentials = credentials;
  
                  //Send the email
                  client.Send(msg);
              }
              catch
              {
                  //Lets the user know if the email has failed
                  lblNotSent.Text = "&lt;div class=\"row\"&gt;" + "&lt;div class=\"col-sm-12\"&gt;" + "There was a problem sending your suggestion. Please try again." 
  
  + "&lt;/div&gt;" + "&lt;/div&gt;" + "&lt;div class=\"form-group\"&gt;" + "&lt;div class=\"col-sm-12\"&gt;" + "If the error persists, please contact Antony." + "&lt;/div&gt;" + 
  
  "&lt;/div&gt;";
              }
              #endregion
  }
  </code></pre>