?
Solved

C# sending mail - error

Posted on 2012-08-30
1
Medium Priority
?
1,068 Views
Last Modified: 2012-09-06
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
0
Comment
Question by:yguyon28
1 Comment
 
LVL 8

Accepted Solution

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

864 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