Sending e-mail in razor/webmatrix, c Sharp

Posted on 2012-09-19
Last Modified: 2012-10-10
I have this code and not sure what is wrong with it: is the to: in WebMail.Send declared correctly?

          var message = "<p>Details of email</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"];
                  [b]  to : "",[/b]
                    subject: "Advertisement confirmation",
                    body: message,
                    isBodyHtml: true
            result = "Your advertisement details have been sent to you by email";

Open in new window

Question by:yguyon28
    1 Comment
    LVL 15

    Accepted Solution

    you can use class System.Net.Mail.SmtpClient();

    protected void SendMail()
        // Gmail Address from where you send the mail
        var fromAddress = "";
        // any address where the email will be sending
        var toAddress = YourEmail.Text.ToString();
        //Password of your gmail address
        const string fromPassword = "Password";
         // Passing the values and make a email formate to display
        string subject = YourSubject.Text.ToString();
        string body = "From: " + YourName.Text + "\n";
        body += "Email: " + YourEmail.Text + "\n";
        body += "Subject: " + YourSubject.Text + "\n";
        body += "Question: \n" + Comments.Text + "\n";
        // smtp settings
        var smtp = new System.Net.Mail.SmtpClient();
            smtp.Host = "";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
            smtp.Timeout = 20000;
        // Passing values to smtp object
        smtp.Send(fromAddress, toAddress, subject, body);

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    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…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now