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 = "[email protected]";
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="[email protected]">
<network host="smtp.live.com"
defaultCredentials="true"
port="587"
userName="[email protected]"
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