I'm still trying to get e-mail to go through using the Demo Email.aspx webform following steps 1-5 of the Try It Out in Chapter 9 at pages 309-310.
When I request Email.aspx in my browser (Internet Explorer 8) I receive this error message:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Net.Mail.MailMessage' to 'System.Net.Mail.MailAddress'
Source Error:
Line 22: myMessage.Body = "Hello World, from Planet Wrox";
Line 23:
Line 24: myMessage.From = new MailMessage("[email protected]", "myName");
Line 25: myMessage.To.Add(new MailAddress("[email protected]", "myName"));
Line 26:
Source File: c:\BegASPNET\Site\Demos\Email.aspx.cs Line: 24
================================================== =======
The code in Email.aspx is:
<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="Email.aspx.cs" Inherits="Email" Title="E-mail Demo" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
</asp:Content>
================================================== ==============
The code in Email.aspx.cs is
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
public partial class Email : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Test Message";
myMessage.Body = "Hello World, from Planet Wrox";
myMessage.From = new MailMessage("[email protected]", "My Name");
myMessage.To.Add(new MailAddress("[email protected]", "My Name"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
}
}
================================================== ================
My web.config settings are:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="My Name <
[email protected]>">
<network host="smtp.ISP.net" userName="
[email protected]" password="mypassword" />
</smtp>
</mailSettings>
</system.net>
================================================== ========
The email addresses I am using are the same as the one I use with Outlook 2007 through the same smtp settings as I use in Outlook 2007. I have been through Chapter 9 so many times I'm almost sick from doing so. I have checked and rechecked multiple times.
I would sure appreciate some assistance in fixing this problem. Thanks for any clue anyone can provide.