Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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 September 21st, 2011, 01:48 PM
Authorized User
Points: 144, Level: 2
Points: 144, Level: 2 Points: 144, Level: 2 Points: 144, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Location: Meridian, Idaho
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
Send a message via MSN to SamuelMSr
Exclamation Need help with Ch9 Exercise please

Ok I have been stumped on this for 3 hours now, have searched all over the net and read a ton of posts here and can not figure out why this is not working.

I am doing the try it out exercises with sending mail and this is the error I am getting no matter what I do:

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. h20sm22992199ani.16
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. h20sm22992199ani.16

Source Error:

Line 46: 
Line 47:             SmtpClient mySmtpClient = new SmtpClient();
Line 48:             mySmtpClient.Send(myMessage);
Line 49: 
Line 50:             Message.Visible = true;


Source File: c:\BegASPNET\Site\Controls\ContactForm.ascx.cs    Line: 48

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. h20sm22992199ani.16]
   System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) +1210331
   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) +97
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1772
   Controls_ContactForm.SendButton_Click(Object sender, EventArgs e) in c:\BegASPNET\Site\Controls\ContactForm.ascx.cs:48
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Here is the information from my web.config file:

Code:
<system.net>
        <mailSettings>
            <smtp deliveryMethod="Network"
             from="Samuel Moren &lt;samuelmsr.developement@gmail.com&gt;">
                <network
                 enableSsl="true"
                 port="587"
                 userName="samuelmsr.developement@gmail.com"
                 password="xxxxxxxx"
                 host="smtp.gmail.com" />
            </smtp>
        </mailSettings>
    </system.net>
And here is the information from my ContactForm.ascx.cs file:

Code:
protected void SendButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string fileName = Server.MapPath("~/App_Data/ContactForm.txt");
            string mailBody = File.ReadAllText(fileName);

            mailBody = mailBody.Replace("##Name##", Name.Text);
            mailBody = mailBody.Replace("##Email##", EmailAddress.Text);
            mailBody = mailBody.Replace("##HomePhone##", PhoneHome.Text);
            mailBody = mailBody.Replace("##BusinessPhone##", PhoneBusiness.Text);
            mailBody = mailBody.Replace("##Comments##", Comments.Text);

            MailMessage myMessage = new MailMessage();
            myMessage.Subject = "Response from the web site";
            myMessage.Body = mailBody;

            myMessage.From = new MailAddress("samuelmsr.developement@gmail.com", "Samuel Moren");
            myMessage.To.Add(new MailAddress("samuelmsr.developement@gmail.com", "Samuel Moren"));

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

            Message.Visible = true;
            FormTable.Visible = false;
        }
    }
I have tried with and without the enableSsl and with and without different ports used by gmail, nothing seems to work. I am guessing I have some stupid simple thing misspelled or a case sensitive problem, but I am not seeing it.

Thank you for any help you may be able to offer!

Sam
 
Old September 21st, 2011, 01:53 PM
Authorized User
Points: 144, Level: 2
Points: 144, Level: 2 Points: 144, Level: 2 Points: 144, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Location: Meridian, Idaho
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
Send a message via MSN to SamuelMSr
Default

BTW: I did do this with the local drop onto my hard drive, and it works fine that way.

I would just love to find out what I am possibly doing wrong, I will be needing to use this in the future, probably quite a lot.

Thanks!
 
Old September 21st, 2011, 01:58 PM
Friend of Wrox
Points: 547, Level: 8
Points: 547, Level: 8 Points: 547, Level: 8 Points: 547, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 125
Thanks: 20
Thanked 3 Times in 3 Posts
Default

Hi Samuel,
Check your application in other internet connection. Some ISP block port 587(and other ports) . It seem's irrelevant but checking it is worth .
Cheers
__________________
Please excuse me for poor and bad English.
 
Old September 21st, 2011, 02:01 PM
Authorized User
Points: 144, Level: 2
Points: 144, Level: 2 Points: 144, Level: 2 Points: 144, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Location: Meridian, Idaho
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
Send a message via MSN to SamuelMSr
Default

Quote:
Originally Posted by morteza View Post
Hi Samuel,
Check your application in other internet connection. Some ISP block port 587(and other ports) . It seem's irrelevant but checking it is worth .
Cheers
Do you think this will matter if I use Outlook 2007 to check the same email address and to send/receive mail?

It uses the same port.
 
Old September 21st, 2011, 02:06 PM
Authorized User
Points: 144, Level: 2
Points: 144, Level: 2 Points: 144, Level: 2 Points: 144, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Location: Meridian, Idaho
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
Send a message via MSN to SamuelMSr
Default

Quote:
Originally Posted by SamuelMSr View Post
Do you think this will matter if I use Outlook 2007 to check the same email address and to send/receive mail?

It uses the same port.
I also have my site uploaded to my development hosting where I put stuff to look at them and show them to people.

http://www.samuelmsr.com

It does not work there either.
 
Old September 21st, 2011, 02:08 PM
Friend of Wrox
Points: 547, Level: 8
Points: 547, Level: 8 Points: 547, Level: 8 Points: 547, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 125
Thanks: 20
Thanked 3 Times in 3 Posts
Default

Quote:
Do you think this will matter if I use Outlook 2007 to check the same email address and to send/receive mail?
Outlook send's email probably without smpt server. Please check it by another ISP that you sure it's 587 port is not blocked.
__________________
Please excuse me for poor and bad English.

Last edited by morteza; September 21st, 2011 at 02:10 PM..
 
Old September 21st, 2011, 02:35 PM
Authorized User
Points: 144, Level: 2
Points: 144, Level: 2 Points: 144, Level: 2 Points: 144, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Location: Meridian, Idaho
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
Send a message via MSN to SamuelMSr
Default

I sent it to 4 friends and they all tried it and it is not working when I upload it to my hosting provider.

I even tried 3 different email addresses.

Every time I debug the issue this is what I get

http://www.samuelmsr.com/debug_error.jpg

I took a snip with the snipping tool so I could just show what it looks like on my screen.
 
Old September 21st, 2011, 02:40 PM
Friend of Wrox
Points: 547, Level: 8
Points: 547, Level: 8 Points: 547, Level: 8 Points: 547, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 125
Thanks: 20
Thanked 3 Times in 3 Posts
Default

So you are out of chance.
Really i don't know what is wrong.
Samuel do you know why my profile indicator has not activity and level bar? It scratch my mind a little.
__________________
Please excuse me for poor and bad English.
 
Old September 21st, 2011, 02:47 PM
Authorized User
Points: 144, Level: 2
Points: 144, Level: 2 Points: 144, Level: 2 Points: 144, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Location: Meridian, Idaho
Posts: 37
Thanks: 13
Thanked 0 Times in 0 Posts
Send a message via MSN to SamuelMSr
Default

Quote:
Originally Posted by morteza View Post
So you are out of chance.
Really i don't know what is wrong.
Samuel do you know why my profile indicator has not activity and level bar? It scratch my mind a little.
I do not know why that is not showing. I just signed up for this forum a couple days ago myself.

Thanks for trying to help anyways, maybe someone else will have an answer to the problem.
 
Old September 21st, 2011, 02:55 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I really don't understand why this doesn't work. Your code and configuration looks fine. To be absolutely sure I just copied and pasted in a new web site, ran it, and it sent the e-mail just fine. Are you really sure the correct web.config (the one in the root, not another one) contains the correct config info?

So, checking this in a mail client such as Outlook may help figuring out what's going on. Additionally, you may want to try to use Telnet and see if you can open a connection to the Gmail server: http://support.microsoft.com/kb/323350 This may work differently on your version of Windows so you may need to Google a bit to find out what to do and how.

When you say "sent to friend", what do you mean? Did you send them the code to test or a link to the site? In the latter case, it won't work for them either as this is a server side issue.

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!
The Following User Says Thank You to Imar For This Useful Post:
SamuelMSr (September 21st, 2011)




Similar Threads
Thread Thread Starter Forum Replies Last Post
Try it out Ch9 pgs 311-312 tjsully BOOK: Beginning ASP.NET 4 : in C# and VB 2 July 16th, 2011 04:46 PM
Ch9 Page 303 - Build error ken evans BOOK: Beginning ASP.NET 4 : in C# and VB 2 October 17th, 2010 10:12 AM
VB Ch9 Try It Out Looping ... p325 Rich57 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 March 7th, 2008 04:57 AM
Multidimensional array in ch9 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 November 2nd, 2004 04:44 PM





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