Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
|
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 April 21st, 2009, 02:16 PM
Registered User
 
Join Date: Apr 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9: The specified string is not in the form required for an e-mail address.

Imar:
This is probably a "no brainer" for you. I'm new to .NET and C# and see the following error on my browser for your Email Demo :

The specified string is not in the form required for an e-mail address.

Source Error:


Line 18: protected void Page_Load(object sender, EventArgs e)Line 19: {Line 20: MailMessage myMessage = new MailMessage();Line 21: myMessage.Subject = "Greetings";Line 22: myMessage.Body = "Hello world, from Planet Wrox";

Source File: c:\BegASPNET\Site\Demos\Email.aspx.cs Line: 20

I have used your downloaded code for this book to verify the code and the webconfig file.


The complete code for the Email.aspx.cs file on my XP computer using VWD is listed below:

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;
publicpartialclassEmail : BasePage
{
protectedvoid Page_Load(object sender, EventArgs e)
{
MailMessage myMessage = newMailMessage();
myMessage.Subject = "Greetings";
myMessage.Body = "Hello world, from Planet Wrox";
myMessage.From = newMailAddress("[email protected]", "myname");
myMessage.To.Add(newMailAddress("[email protected]", "myname"));
SmtpClient mySmtpClient = newSmtpClient();
mySmtpClient.Send(myMessage);
}
}

My code for the Email.aspx under the Demos folder is listed below:

<%@PageLanguage="C#"Debug="true"MasterPageFile="~/MasterPages/MasterPage.master"AutoEventWireup="true"CodeFile="Email.aspx.cs"Inherits="Email"Title="E-mail Demo" %>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
</
asp:Content>
<
asp:ContentID="Content2"ContentPlaceHolderID="cpMainContent"Runat="Server">
</
asp:Content>

All feedback is appreciated.
v/r,
gfmann

Last edited by gfmann; April 21st, 2009 at 02:21 PM..
 
Old April 21st, 2009, 05:23 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Is this the actual code you're executing? Or did you modify the addresses before you posted here? The current addresses seem fine to me, so those shouldn't be a problem. The error you get is typically thrown when you enter an invalid To or From address, like "you" instead of [email protected].

And how does your <system.net /> element in web.config look?

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 April 21st, 2009, 09:49 PM
Registered User
 
Join Date: Apr 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Wink Chapter 9: The specified string is not in the form required for an e-mail address.

Imar:
Thank you for your quick response.

To answer your questions from your email to me:

Is this the actual code you're executing? No

Or did you modify the addresses before you posted here? Modified the addresses.
From my email.aspx file:

public partial class Email : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Greetings";
myMessage.Body = "Hello world, from Planet Wrox";

myMessage.From = new MailAddress("[email protected]", "Gay");
myMessage.To.Add(new MailAddress("[email protected]", "Gay Farace-Mann"));

SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.EnableSsl = false;
mySmtpClient.Send(myMessage);
}
}

The current addresses seem fine to me, so those shouldn't be a problem. The error you get is typically thrown when you enter an invalid To or From address, like "you" instead of [email protected].

And how does your <system.net /> element in web.config look?
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="gay-faracemann&lt;@cox.net&gt;">
<network host="smtp.west.cox.net" userName="gay-faracemann" password="Boysare2!"/>
</smtp>
</mailSettings>
</system.net>


v/r,
gfmann





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Required in Mail / dparsons balesh ASP.NET 1.0 and 1.1 Professional 3 November 6th, 2006 08:18 AM
Changing the senders email address in the mail() rinventive Beginning PHP 1 May 23rd, 2006 10:24 PM
E-mail Address Changes Ben Horne Forum and Wrox.com Feedback 1 April 1st, 2004 04:43 PM
Verify for Valid E-mail address eapsokha Classic ASP Professional 2 February 24th, 2004 12:29 AM





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