Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 May 6th, 2012, 04:13 PM
Authorized User
 
Join Date: Apr 2012
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Armaan
Default Email

sir
i have implemented the "Sending email message" try it out exercise on page 319.
It works well for ”SpecifiedPickupDirectory”.But when i tried to send an email message through network it gives error message that "smtp exception was unhandled by the user code".
I am sending you my web.config file and Email page .

web.config
Code:
<?xml version="1.0"?>
<configuration>
	<system.web>
    <pages theme="DarkGrey">
      <controls>
        <add tagPrefix="Wrox" tagName="Banner" src="~/Controls/Banner.ascx" />
      </controls>
    </pages>
		<compilation debug="true" targetFramework="4.0"/>
	</system.web>
    <system.net>
      <mailSettings>
        <smtp deliveryMethod="Network"
                 from="arman &lt;[email protected]&gt;">
          <network host="smtp.yahoo.com" />
        </smtp>
      </mailSettings>
    </system.net>
</configuration>
code behind of email page

Code:
using System.Net.Mail;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class site_Demos_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 MailAddress("[email protected]", "arman");
    myMessage.To.Add(new MailAddress("[email protected]", "asjad"));

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

Please guide
 
Old May 6th, 2012, 04:27 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You need to specify a user name and password as shown in the book. Also, Yahoo may require a portnumber as well; see the book for examples.

Cheers,

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 May 7th, 2012, 01:11 AM
Authorized User
 
Join Date: Apr 2012
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Armaan
Default Email

sir now i specified the username and password. But i don't know how to specify the port number. You have told us possible range of the port number in the book. But how can we determine the exact port number?
Please guide
 
Old May 7th, 2012, 01:26 AM
Authorized User
 
Join Date: Mar 2012
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default Yahoo Config

Hi,

If you have a look at http://answers.yahoo.com/question/in...4165102AAAVBA1 it looks like the smtp port number for Yahoo is 465 using SSL.

Therefore your web .config file should like something like:-

<network enableSsl="true" userName="your_user_name" password="your_password" host="smtp.mail.yahoo.com" port="465"/>

Hope this helps.

Cheers,

Ian
 
Old May 7th, 2012, 01:54 AM
Authorized User
 
Join Date: Apr 2012
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Armaan
Default Email

sir here is my web.config file code
Code:
<?xml version="1.0"?>
<configuration>
	<system.web>
    <pages theme="DarkGrey">
      <controls>
        <add tagPrefix="Wrox" tagName="Banner" src="~/Controls/Banner.ascx" />
      </controls>
    </pages>
		<compilation debug="true" targetFramework="4.0"/>
	</system.web>
    <system.net>
      <mailSettings>
        <smtp deliveryMethod="Network"
                 from="arman &lt;[email protected]&gt;">
          <network enableSsl="true" userName="arman" password="my_password" host="smtp.mail.yahoo.com" port="465"/>
        </smtp>
      </mailSettings>
    </system.net>
</configuration>
and here is email.aspx.cs code
Code:
using System.Net.Mail;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class site_Demos_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 MailAddress("[email protected]", "arman");
    myMessage.To.Add(new MailAddress("[email protected]", "arman"));

    SmtpClient mySmtpClient = new SmtpClient();
    mySmtpClient.Send(myMessage);
    }
}
Now i have implemented all the code according to your instruction. But it still does not work. i have bolded the line which shows error.
Now what may be the problem at this line?
 
Old May 7th, 2012, 03:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

What's the erorr you are getting?

Also, are you sure your user name is correct? Have you tried passing in your full account name, with and without the @yahoo.com part?

Otherwise, try Google for

SmtpClient Yahoo web.config

and you'll find various examples of config code that worked. I don't use Yahoo, so I am not 100% sure what you need to configure.

Cheers,

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
email kirangentlebreeze1987 Visual Web Developer 2008 6 December 13th, 2009 01:21 AM
C# and Email iceman90289 C# 2005 8 June 25th, 2008 11:44 AM
email keyvanjan Classic ASP Basics 2 March 20th, 2006 12:05 AM
Sending email maitias C# 2005 2 February 17th, 2006 11:24 AM





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