WebMail and WebMatrix

Discussion in 'General troubleshooting' started by Gecko, Jul 4, 2011.

  1. I am trying to build a Contact page via WebMatrix using ASP.net Tutorial 11 (http://www.asp.net/webmatrix/tutorials/11-adding-email-to-your-web-site).

    The code for the ProcessRequest.cshtml page is:

    Code:
    @{
        var customerName = Request["customerName"];
        var customerRequest = Request["customerRequest"];
        try {
            // Initialize WebMail helper
            WebMail.SmtpServer = "your-SMTP-host";
            WebMail.SmtpPort = 25;
            WebMail.EnableSsl = true;
            WebMail.UserName = "your-user-name-here";
            WebMail.From = "your-email-address-here";
            WebMail.Password = "your-account-password";
    
            // Send email
            WebMail.Send(to: "target-email-address-here",
                subject: "Help request from - " + customerName,
                body: customerRequest
            );
        }
        catch (Exception ex ) {
            <text>
                <b>The email was <em>not</em> sent.</b>
                The code in the ProcessRequest page must provide an
                SMTP server name, a user name, a password, and
                a "from" address.
            </text>
        }
    }
    The instructions said to:

    - Set "your-SMTP-host" to the name of the SMTP server that you have access to.
    - Set "your-user-name-here" to the user name for your SMTP server account.
    - Set "your-email-address-here" to your own email address. This is the email address that the message is sent from.
    - Set "your-account-password" to the password for your SMTP server account.
    - Set "target-email-address-here" to the email address of the person you want to send the message to. Normally this would be the email address of the recipient. For testing, though, you want the message to be sent to you. Therefore, set this to your own email address. When the page runs, you'll receive the message.

    I made the appropriate changes:

    Code:
    // Initialize WebMail helper
        WebMail.SmtpServer = "smtp.mydomain.com";
        WebMail.SmtpPort = 25;
        WebMail.EnableSsl = true;
        WebMail.UserName = "[email protected]";
        WebMail.From = "[email protected]";
        WebMail.Password = "password";
    
    // Send email
        WebMail.Send(to: "[email protected]",
          subject: "Request for Information from - " + customerName,
          body: customerRequest
        );
    When I ran it, I got the following:

    The email was not sent. The code in the ProcessRequest page must provide an SMTP server name, a user name, a password, and a "from" address.

    Since I knew I had provide the blah blah blah, I made the following code change to find out exactly what my error was:

    Code:
    catch (Exception ex ) {
        @ex.Message
        //<text>
          //<b>The email was <em>not</em> sent.</b>
          //The code in the ProcessRequest page must provide an
          //SMTP server name, a user name, a password, and
          //a "from" address.
        //</text>
      }
    And I got the following error:

    Server does not support secure connections.

    So I go in and I change the "WebMail.EnableSsl" from 'true' to 'false' and I got the following error:

    Mailbox unavailable. The server response was: <[email protected]> No such user here

    I tried several different email domain accounts and got the same result. I even added a 'customerEmail' variable and placed it withing the "target-email-address-here" and the first time it told me it was an invalid email string and then I removed the quotes and the "Mailbox unavailable" error.

    At this point...I don't know if it's my code or discountASP.net; however, I DO know that I am getting really frustrated. Any assistance or suggestions is greatly appreciated. Thank you.
     
  2. Not sure but I think the smtp server should be set to: localhost
     
  3. Yes. And SSL should not be used.
     

Share This Page