Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 February 10th, 2009, 11:08 PM
Registered User
 
Join Date: May 2008
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 9 p. 310

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 &lt;[email protected]&gt;">
<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.
 
Old February 11th, 2009, 04:56 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Featheriver,

Take a look at this:

myMessage.From = new MailMessage("[email protected]", "My Name");
myMessage.To.Add(new MailAddress("[email protected]", "My Name"));


You're constructing a MailMessage instead of a MailAddress. Simply change MailMessage to MailAddress:

myMessage.From = new MailAddress("[email protected]", "My Name");
myMessage.To.Add(new MailAddress("[email protected]", "My Name"));


Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 11th, 2009, 11:11 AM
Registered User
 
Join Date: May 2008
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 9 p. 310 -- Problem solved

Imar, don't know what I'd do without you. You neatly zeroed in where my error lay. You know, I've truly been through that Email.aspx section of Chapter 9 perhaps a dozen times and never saw that MailMessage vs MailAddress error.

Funny how one can look at something and not see it. Guess it is my age. I'm 76 years old and losing it.

Thank you so much. I made the change you pointed out and--voila!--the mail came through just as it should.

Thank you very very much!
 
Old February 11th, 2009, 04:44 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Don't worry about it; it's not an age thing. I can have code like this staring me in the face as well ;-)

A second set of eyes is always very useful...

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM
SCWCD Exam 310-081 Books weitn J2EE 4 November 15th, 2004 10:46 AM





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