using System;
using ComponentPro.Net.Mail;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// Handles the Send button's Click event.
    /// </summary>
    /// <param name="sender">The button object.</param>
    /// <param name="e">The event arguments.</param>
    protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {
            // Create a new message object.
            MailMessage msg = new MailMessage();
            msg.From.Add(txtFrom.Text);
            msg.To.Add(txtTo.Text);
            msg.Subject = txtSubject.Text;
            msg.BodyText = txtContent.Text;

            string emlfile = AppDomain.CurrentDomain.BaseDirectory + "\\Message.eml";
            msg.Save(emlfile);

            // Save as...
            Response.AppendHeader("content-disposition", "attachment; filename=\"" + "Message.eml" + "\"");
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(emlfile);
            Response.End();
        }
        catch (Exception exc)
        {
            lblResult.Text = string.Format(null, "Exception: {0}", exc.Message);
        }
    }
}