C# sending mail - error

I have this piece of code bellow and I get the following error.

    Page.Title = "Post Your Advertisement";
    var result = "";
            ModelState.AddError("title", "Please provide a title");
        if(Request["title"].Length > 200){
            ModelState.AddError("title", "Your title cannot exceed 200 characters");
            ModelState.AddError("description", "You must provide a description");
            ModelState.AddError("duration", "Please choose a duration");
            ModelState.AddError("price", "Please provide a price");
        if(!Request["price"].IsDecimal () && !Request["Price"].IsEmpty()){
            ModelState.AddError("price", "Please provide a valid number for the price");
            ModelState.AddError("condition", "Please state the condition of your item");
            ModelState.AddError("email", "Please provide your email address");
        if(!Request["email"].IsEmpty() && !Functions.IsValidEmail(Request["Email"])){
            ModelState.AddError("email", "Please provide a valid email address");
            ModelState.AddFormError(@"Please fix the errors below 
                                    before submitting the form");
            var message = "<p>Details of your item for sale:</p>";
            message += "Title: " + Request["title"] + "<br />";
            message += "Description: " + Request["description"] + "<br />";
            message += "Duration: " + Request["duration"] + " days<br />";
            message += "Price: " + String.Format("{0:c}", Request["price"].AsFloat()) + "<br />";
            message += "Condition: " + Request["condition"];
                    to: Request["email"],
                    subject: "Advertisement confirmation",
                    body: message,
                    isBodyHtml: true
            result = "Your advertisement details have been sent to you by email";
<form id="post-advert" action="@Href("~/Sell")" method="post">
        <legend>Post Your Advertisement</legend>
            <label for="title">Title*</label>
            <input type="text" id="title" name="title" value="@Request["title"]" />
            <label for="description">Description*</label>
            <textarea id="description" name="description">@Request["description"]</textarea>
            <label for"duration">Duration*</label>
            <select id="duration" name="duration">
                <option value="">--Choose one--</option>
                <option value="1" @Helpers.Selected("duration","1")>1 Day</option>
                <option value="3" @Helpers.Selected("duration","3")>3 Days</option>
                <option value="7" @Helpers.Selected("duration","7")>7 Days</option>
                <option value="14" @Helpers.Selected("duration","14")>14 Days</option>
           <label for="price">Price*</label>
            <input type="text" id="price" name="price" value="@Request["price"]" />
            <label for="condition">Condition*</label>
            <input type="radio" id="condition" name="condition" value="Fair" @Helpers.Checked("condition","Fair") />Fair 
            <input type="radio" id="condition" name="condition" value="Good" @Helpers.Checked("condition","Good") />Good 
            <input type="radio" id="condition" name="condition" value="As New" @Helpers.Checked("condition","As New") />As New 
            <label for="email">Your Email Address*</label>
            <input type="text" id="email" name="email" value="@Request["email"]" />
            <input type="submit" name="Submit" value="Post" />

Open in new window


Server Error in '/' Application.
Could not find a part of the path 'C:\Mail\f0a8e85e-fe75-477e-a23c-02f47b9a7c4b.eml'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Mail\f0a8e85e-fe75-477e-a23c-02f47b9a7c4b.eml'.

Source Error:

Line 41:             message += "Price: " + String.Format("{0:c}", Request["price"].AsFloat()) + "<br />";
Line 42:             message += "Condition: " + Request["condition"];
Line 43:             WebMail.Send(
Line 44:                     to: Request["email"],
Line 45:                     subject: "Advertisement confirmation",

Source File: c:\webmatrix\Final Code\Chapter5\Classifieds\Sell.cshtml    Line: 43

Stack Trace:

[DirectoryNotFoundException: Could not find a part of the path 'C:\Mail\f0a8e85e-fe75-477e-a23c-02f47b9a7c4b.eml'.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +224
   System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) +1142
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +78
   System.IO.FileStream..ctor(String path, FileMode mode) +71
   System.Net.Mail.SmtpClient.GetFileMailWriter(String pickupDirectory) +163
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1206

[SmtpException: Failure sending mail.]
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1829
   System.Web.Helpers.WebMail.Send(String to, String subject, String body, String from, String cc, IEnumerable`1 filesToAttach, Boolean isBodyHtml, IEnumerable`1 additionalHeaders) +617
   ASP._Page_Sell_cshtml.Execute() in c:\webmatrix\Final Code\Chapter5\Classifieds\Sell.cshtml:43
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207
   System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +68
   System.Web.WebPages.WebPage.ExecutePageHierarchy() +156
   System.Web.WebPages.StartPage.RunPage() +19
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +65
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
   System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContext context) +249
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

to me it looks like "C:\Mail\f0a8e85e-fe75-477e-a23c-02f47b9a7c4b.eml" is not accessible by the code.can you make sure?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.