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 August 8th, 2010, 06:49 AM
Registered User
 
Join Date: Aug 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 9 Email problem

Hi Imar

First of all i want to say how helpful i am finding your book. Im a classic ASP Classic developer learning .net in c# and your book is quite simply the best i have found.

I am, however struggling, with the email settings. I have a hotmail account and when i try and load th demo page (as per page 310 of your book) i get the following error

Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated

This is with mySmtpClient.EnableSsl = true;
If i take that out i get a different error message

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

My code is as follows

Code behind the demo email page ...

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 Email : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Test Message";
myMessage.Body = "Hellow world, from planet Wrox";
myMessage.From = new MailAddress("dariune99@hotmail.com", "Alex Eichner");
myMessage.To.Add(new MailAddress("dariune99@hotmail.com", "Alex Eichner"));

SmtpClient mySmtpClient = new SmtpClient();

mySmtpClient.Send(myMessage);
}
}

Web.config

<system.net>
<mailSettings>
<smtp from="me@hotmail.com" deliveryMethod="Network">
<network host="smtp.live.com" port="587"
userName="me@hotmail.com" password="password" defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
</configuration>
 
Old August 8th, 2010, 07:06 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 Dariune,

Quote:
First of all i want to say how helpful i am finding your book. Im a classic ASP Classic developer learning .net in c# and your book is quite simply the best i have found.
Thank you; good to hear!

Try changing the port to 25; somehow it seems that Hotmail requires port 25, despite the fact you're using SSL. You need to set ENableSsl to true again.

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 August 8th, 2010, 07:22 AM
Registered User
 
Join Date: Aug 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Imar, thanks for the quick reply :)

I have done as you said and im afraid i get the following error again ...

Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated

Any other ideas?
 
Old August 8th, 2010, 07:29 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You also need to take out defaultCredentials="true"; then it works for me with this config:

Code:
<system.net>
  <mailSettings>
    <smtp from="me@someaddress.com" deliveryMethod="Network">
      <network host="smtp.live.com" port="25" userName="me@someaddress.com" 
                 password="mypassword" />
    </smtp>
  </mailSettings>
</system.net>
and this code behind:
Code:
 
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Test Message";
myMessage.Body = "Hellow world, from planet Wrox";
myMessage.From = new MailAddress("me@someaddress.com");
myMessage.To.Add(new MailAddress("me@someaddress.com"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.EnableSsl = true;
mySmtpClient.Send(myMessage);
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!
The Following User Says Thank You to Imar For This Useful Post:
Dariune (August 8th, 2010)
 
Old August 8th, 2010, 07:48 AM
Registered User
 
Join Date: Aug 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Imar thats done it.

Thankyou so much for your help. Its very much apreciated.

Now lets see if i cant get that chapter finished :)
 
Old August 9th, 2010, 03:17 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome....

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 September 1st, 2010, 03:56 AM
Authorized User
 
Join Date: Oct 2009
Posts: 40
Thanks: 4
Thanked 0 Times in 0 Posts
Default EMAIL HELP AGAIN IMAR

Hi Imar. You'll remember when i was going through the book the first time around i didnt get the email to work. This is my second go at the book and ive studied Dariune and your discussion below carefully to see if i could get it to work as im using hotmail but still no luck. This was the error i got below if you can point me in the right direction. Must try get it to work this time as i didnt realise how much the rest of the book used email until ive done it the first time around:

Code:
Server Error in '/' Application.
--------------------------------------------------------------------------------

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 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.Mail.SmtpException: 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

Source Error: 

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.  

Stack Trace: 


[SmtpException: 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]
   System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) +1061671
   System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) +41
   System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) +101
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1480
   Practice_Email.Page_Load(Object sender, EventArgs e) +169
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Code for the demo email page:
Code:
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 Practice_Email : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MailMessage myMessage = new MailMessage();
        myMessage.Subject = "Practice Message";
        myMessage.Body = "Hello guys, this is an email from Salford Student Bookshop";

        myMessage.From = new MailAddress("leemark2k3@hotmail.com", "Lee Bell");
        myMessage.To.Add(new MailAddress("leemark2k3@hotmail.com", "Lee Bell"));

        SmtpClient mySmtpClient = new SmtpClient();
        mySmtpClient.Send(myMessage);
    }
}
web.config code:

Code:
  <system.net>
    <mailSettings>
      <smtp from="me@hotmail.com" deliveryMethod="Network">
        <network host="smtp.live.com" port="25"
        userName="leemark2k3@hotmail.com" password="*******"  />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>

Last edited by leemark2k3; September 1st, 2010 at 08:21 PM..
 
Old September 1st, 2010, 04:04 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I don't see you setting EnableSsl to true in your code.

Also, you may want to edit your post and remove your hotmail user name and password.

Finally, did you try the local drop folder as I explained previously? It's super simple and makes all of this a lot easier.....

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!
The Following User Says Thank You to Imar For This Useful Post:
leemark2k3 (September 1st, 2010)
 
Old September 1st, 2010, 08:34 PM
Authorized User
 
Join Date: Oct 2009
Posts: 40
Thanks: 4
Thanked 0 Times in 0 Posts
Default

Ive got it to work Imar, Hurrah! Thanks for the advice.
 
Old September 1st, 2010, 10:50 PM
Authorized User
 
Join Date: Oct 2009
Posts: 40
Thanks: 4
Thanked 0 Times in 0 Posts
Default

I successfully managed to send the message to my hotmail inbox as per step 5 on p310.

However when sending mail via the contactform page per step 8 on p.316 it gives the following error:

Server Error in '/' Application.
-------------------------------------------------------------------------

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
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: 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

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:


[SmtpException: 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]
System.Net.Mail.MailCommand.CheckResponse(SmtpStat usCode statusCode, String response) +1061671
System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) +41
System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) +101
System.Net.Mail.SmtpClient.Send(MailMessage message) +1480
Controls_ContactUs.buttonSend_Click(Object sender, EventArgs e) +392
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint



Here is my code that had succesfully sent the message to my inbox on page 310 but came up with the error im telling you about:

button send click method:
Code:
protected void buttonSend_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string fileName = Server.MapPath("~/App_Data/ContactUs.txt");
            string mailBody = System.IO.File.ReadAllText(fileName);

            mailBody = mailBody.Replace("##Name##", textName.Text);
            mailBody = mailBody.Replace("##Email##", textEmailAddress.Text);
            mailBody = mailBody.Replace("##HomePhone##", homePhone.Text);
            mailBody = mailBody.Replace("##MobilePhone##", mobilePhone.Text);
            mailBody = mailBody.Replace("##Comments##", textComments.Text);

            MailMessage myMessage = new MailMessage();
            myMessage.Subject = "Query from Salford Student Books User";
            myMessage.Body = mailBody;

            myMessage.From = new MailAddress("leemark2k3@hotmail.com", "Farid Menziane");
            myMessage.To.Add(new MailAddress("leemark2k3@hotmail.com", "Lee Bell"));

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

            LabelMessage.Visible = true;
            FormTable.Visible = false;
        }

    }
contactus.txt:

Code:
Dear Staff member,

The following user has sent a query to us. Please see below:

Name:                    ##Name##
E-mail address:          ##Email##
Home telephone:          ##HomePhone##
Mobile phone:            ##MobilePhone##
Comments:                ##Comments##
Thanks if you can help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 9 Trying to send email out digink BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 March 5th, 2011 05:42 AM
Chapter 9 Can't send email ChuckASP BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 22nd, 2010 12:16 PM
Chapter 9 - email security ChuckASP BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 March 20th, 2010 03:26 PM
Chapter 3 - Email List daibhidh BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 6 December 4th, 2009 06:39 AM
Chapter 11 - Email HELP! Nyika1203 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 28th, 2008 06:45 PM





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