Wrox Programmer Forums
|
BOOK: Beginning ASP.NET Web Pages with WebMatrix
This is the forum to discuss the Wrox book Beginning ASP.NET Web Pages with WebMatrix by Mike Brind, Imar Spaanjaars ; ISBN: 978-1-1180-5048-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Web Pages with WebMatrix section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 17th, 2011, 09:55 PM
Authorized User
 
Join Date: Mar 2010
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Default Chapter 5, WebMail Helper

Working my way through, I've run into problems in Chapter 5, with the WebMail Helper.

Here's the applicable section from Sell.cshtml:
Code:
        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";
        }
I began by using the _AppStart.cshtml file of

Code:

     WebMail.SmtpServer = "smtp.live.com"; 
     WebMail.SmtpPort = 587; 
     WebMail.EnableSsl = false; 
     WebMail.UserName = "username@hotmail.com"; 
     WebMail.From = "WebmatrixChap5"; 
     WebMail.Password = "password";
But got a ' "SmptServer" was not specified' error.

So I tried using web.config (changing the name of _AppStart so there shouldn't be a conflict) with:

Code:
<?xml version="1.0"?>

<configuration>
    <system.web>
        <compilation debug="false" targetFramework="4.0" />
    </system.web>
    <system.net>
        <mailSettings>
			<smtp from="username@hotmail.com">
				<network host="smtp.live.com" 
                 defaultCredentials="true" 
                 port="587" 
                 userName="myusername@hotmail.com" 
                 password="password"/>
            </smtp>
        </mailSettings>
    </system.net>
</configuration>
The error changes to 'The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first'

Both error messages tell me the error is in this line:
Code:
Line 42:             WebMail.Send(
(continues with 
Line 43:                     to: Request["email"],
Line 44:                     subject: "Advertisement confirmation",
I used the smtp settings that I used in Imar's Beginning ASP.NET 3.5 book and they work fine.

I've searched for an answer (both on this site and internmet-wide) and can't find an answer. Any help?

Thanks,
John
 
Old December 18th, 2011, 04:11 AM
Wrox Author
 
Join Date: Dec 2011
Posts: 57
Thanks: 1
Thanked 19 Times in 19 Posts
Default

Change EnableSsl to true, and provide an email address to the From property:
Code:
     WebMail.SmtpServer = "smtp.live.com"; 
     WebMail.SmtpPort = 587; 
     WebMail.EnableSsl = true; 
     WebMail.UserName = "username@hotmail.com"; 
     WebMail.From = "username@hotmail.com"; 
     WebMail.Password = "password";
 
Old January 6th, 2012, 10:34 AM
Authorized User
 
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

Hi I am having a similar issue. I set EnableSSL to true and I get the following error:

An existing connection was forcibly closed by the remote host
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.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

Source Error:

Line 40: message += "<br />";
Line 41: message += "Condition: " + Request["condition"];
Line 42: WebMail.Send(
Line 43: to: Request["email"],
Line 44: subject: "Advertisement Confirmation",




My _AppStart file code.

Code:
@{
    WebMail.SmtpServer = "smtp.mail.yahoo.com";
    WebMail.SmtpPort = 465;
    WebMail.EnableSsl = true;
    WebMail.UserName = "xxx";
    WebMail.Password = "xxxx";
    WebMail.From = "xxxx@yahoo.com";
}
 
Old February 9th, 2012, 05:05 PM
Authorized User
 
Join Date: Mar 2011
Posts: 74
Thanks: 21
Thanked 2 Times in 2 Posts
Default Also Having Email Issues

Here is my code:

Code:
@{ 
        var customerName = Request["customerName"];
        var customerRequest = Request["customerRequest"];     
        try {        
            // Initialize WebMail helper        
            WebMail.SmtpServer = "excsrv01";        
            WebMail.SmtpPort = 587;        
            WebMail.EnableSsl = true;        
            WebMail.UserName = "abc02";        
            WebMail.From = "lastname.first@companyname.edu";         
            WebMail.Password = "password";         
            
            // Send email        
            WebMail.Send(to: "lastname.first@companyname.edu",            
                        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>     
        } 
  }
Please note: I am using a Microsoft Exchange Server (behind the corporate firewall) and using Microsoft Outlook. I've used WebMail.SmtpPort = 25; and also used a few other names for the WebMail.SmtpServer = "excsrv01"; Have been able to discover Microsoft Exchange Server has "excsrv01 all the way up to excsrv40 and probably beyond. Also tried WebMail.SmtpServer = "excsrv01@companyname.edu"; So maybe it's just I haven't hit the right server?

Last edited by jpjamie; February 9th, 2012 at 05:10 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
webmail avik_u Javascript 0 October 31st, 2007 04:29 PM
Using Keyboard in the Webmail Application pannet1 CSS Cascading Style Sheets 1 March 26th, 2007 11:38 AM
SQLMail through webmail? vgv8 SQL Server 2000 0 December 2nd, 2004 10:29 AM
webmail - with errors bad_demon Beginning PHP 2 November 14th, 2003 08:22 AM
WebMail Project Help sidneyfuerte Classic ASP Professional 1 August 19th, 2003 10:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.