C# sending mail - error

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

@{
    Page.Title = "Post Your Advertisement";
    var result = "";
    if(IsPost){
        if(Request["title"].IsEmpty()){
            ModelState.AddError("title", "Please provide a title");
        }
        if(Request["title"].Length > 200){
            ModelState.AddError("title", "Your title cannot exceed 200 characters");
        }
        if(Request["description"].IsEmpty()){
            ModelState.AddError("description", "You must provide a description");
        }
        if(Request["duration"].IsEmpty()){
            ModelState.AddError("duration", "Please choose a duration");
        }
        if(Request["price"].IsEmpty()){
            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");
        }
        if(Request["condition"].IsEmpty()){
            ModelState.AddError("condition", "Please state the condition of your item");
        }
        if(Request["email"].IsEmpty()){
            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");
        }
        if(!ModelState.IsValid){
            ModelState.AddFormError(@"Please fix the errors below 
                                    before submitting the form");
        }
        else{
            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"];
            WebMail.Send(
                    to: Request["email"],
                    subject: "Advertisement confirmation",
                    body: message,
                    isBodyHtml: true
                    );
            result = "Your advertisement details have been sent to you by email";
        }
    }
}
<div>@result</div>
<form id="post-advert" action="@Href("~/Sell")" method="post">
    <fieldset>
        <legend>Post Your Advertisement</legend>
        @Html.ValidationSummary(true)
        <div>
            <label for="title">Title*</label>
        </div>
        <div>
            <input type="text" id="title" name="title" value="@Request["title"]" />
            @Html.ValidationMessage("title")
        </div>
        <div>
            <label for="description">Description*</label>
        </div>
        <div>
            <textarea id="description" name="description">@Request["description"]</textarea>
            @Html.ValidationMessage("description")
        </div>
        <div>
            <label for"duration">Duration*</label>
        </div>
        <div>
            <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>
            </select>
            @Html.ValidationMessage("duration")
        </div>
        <div>
           <label for="price">Price*</label>
        </div>
        <div>
            <input type="text" id="price" name="price" value="@Request["price"]" />
            @Html.ValidationMessage("price")
        </div>
        <div>
            <label for="condition">Condition*</label>
        </div>
        <div>
            <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 
            @Html.ValidationMessage("condition")
        </div>
        <div>
            <label for="email">Your Email Address*</label>
        </div>
        <div>
            <input type="text" id="email" name="email" value="@Request["email"]" />
            @Html.ValidationMessage("email")
        </div>
        <div>
            <input type="submit" name="Submit" value="Post" />
        </div>
    </fieldset>
</form>

Open in new window


error...


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
yguyon28Asked:
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.

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

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
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.