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 June 14th, 2012, 08:23 AM
Registered User
 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default SMTP EMAIL NOT WORKING

Hi Imar,

I'm currently in the excercise how to send email from ur web page.
The Specifiedpickupdirectory is working fine bt sending from mail to mail not working as it says timeout expired.

As i've already searched the forums and couldn't able to get a solution. Another guy is also having the same problem as i in which he also needs solution. But he's having a different error. so please help me to get a solution.

Here's my code

Code:
Email.aspx.cs
-------------

protected void Page_Load(object sender, EventArgs e)
    {
        MailMessage myMessage = new MailMessage();
        myMessage.Subject = "Text Message";
        myMessage.Body = "Hello World, Welcome To Planet Wrox";
        myMessage.From = new MailAddress("my@gmail.com", "Developer");
        myMessage.To.Add(new MailAddress("my@gmail.com", "Developer"));

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


Web.config
-----------

<?xml version="1.0"?>

<configuration>

  <system.web>
        <compilation debug="true" targetFramework="4.0" />
      <pages theme ="Monochrome">
        <controls>
          <add tagName="Banner" tagPrefix="Wrox" src ="~/Controls/Banner.ascx"/>
        </controls>
      </pages>
    </system.web>
  <system.net>
  <mailSettings>
    <!--<smtp deliveryMethod ="SpecifiedPickupDirectory">
      <specifiedPickupDirectory pickupDirectoryLocation ="c:\TempMail" />-->
    <smtp deliveryMethod="Network" from="my@gmail.com">
      <network enableSsl ="true" userName="myusername" password="mypassword" host="smtp.gmail.com" port="465"/>
    </smtp>
    
    <!--<smtp deliveryMethod="Network" from="&lt;myemail&gt;">
      <network enableSsl="true" userName="username" password="pwd" host="smtp.gmail.com" port="587"/>
    </smtp>-->
  </mailSettings>
  </system.net>
</configuration>

Last edited by Rajasekar1988; June 15th, 2012 at 12:23 AM..
 
Old June 14th, 2012, 08:54 AM
Authorized User
 
Join Date: Mar 2012
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Hi Rajasekar,

I have had this problem before and from what I can see from your web.config file you have actually commented out the correct solution.

With gmail you must connect to port 587 and not 465 to send mail via smtp.

Hope this helps.

Kind regards,

Ian Ryder.
 
Old June 15th, 2012, 12:27 AM
Registered User
 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I commented those lines because it's not worked properly. that's y i commented it
 
Old June 15th, 2012, 02:36 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 agree with Ian: the code you commented out should work. A few things to check:

1. Use your full Gmail user name. That is, not userName, but userName@gmail.com

2. Make sure your network is allowed to reach smtp.gmail.com over port 587. Maybe your network administrator doesn't allow traffic to go over that port?

3. Take a look at this:

from="&lt;myemail&gt;"

The from attribute should contain at least a valid e-mail address; not just your name. This means you need to remove the < and > symbols.

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 June 15th, 2012, 03:27 AM
Registered User
 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Imar,
I did exactly what Ian told. I used port 587. but now i'm getting this error.

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

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
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.5.1 Authentication Required. Learn more at

Source Error:


Line 30:
Line 31: SmtpClient mySmtpClient = new SmtpClient();
Line 32: mySmtpClient.Send(myMessage);
Line 33: }
Line 34: }


Source File: c:\Users\Developer\Documents\Visual Studio 2010\WebSites\WebSite1\Demos\Email.aspx.cs Line: 32

Stack Trace:


[SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at]
System.Net.Mail.MailCommand.CheckResponse(SmtpStat usCode statusCode, String response) +1209995
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
Demos_Email.Page_Load(Object sender, EventArgs e) in c:\Users\Developer\Documents\Visual Studio 2010\WebSites\WebSite1\Demos\Email.aspx.cs:32
System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

And this is my new Web.config file settings
-----------------------------------------
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="my@gmail.com">
<network enableSsl ="true" userName="my@gmail.com" password="pwd" host="smtp.gmail.com" port="587"/>
</smtp>
</mailSettings>
</system.net>

Please help me to resolve this issue
 
Old June 15th, 2012, 04:08 AM
Authorized User
 
Join Date: Mar 2012
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Hi Rajasekar,

Your web.config file looks fine.

Since I use gmail myself, to test your snippet, I copied your web.config code into my own web.config file and changed the "from", "username" and "password" to my own credentials. The email sent fine?

Therefore, this would imply that your code is correct but there is something wrong with the username and/or password. To test your credentials go to www.gmail.com and log in to your account. If you can login then these are the credentials you need to use in the web.config file.

Hope that helps, but if not, I will need to leave it to the master (Imar) to guide you further.

Good Luck and Kind regards,

Ian
 
Old June 15th, 2012, 05:23 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 may also want to look at the suggestions made here: http://stackoverflow.com/questions/7...r-with-c-sharp

Some relate to anti-virus software and others to changing your password. One of them might have the answer for you....

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 June 15th, 2012, 05:26 AM
Registered User
 
Join Date: Jun 2012
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Ian,
Yes my web.config setting is correct. I checked it with my hotmail account. its working fine and i could able to send email.

I verified my account details in gmail it works fine.

but when i use my gmail account details in web.config only the error which i posted last is popping up.

so its not working for gmail only.

Please help me to get a soultion..





Similar Threads
Thread Thread Starter Forum Replies Last Post
SMTP Email problems vbboyd BOOK: Beginning ASP.NET 4 : in C# and VB 5 March 7th, 2012 08:49 AM
SMTP Email question snufse ASP.NET 2.0 Basics 2 July 9th, 2009 11:08 AM
SMTP Email Error Handling Ron Howerton Pro Visual Basic 2005 1 July 12th, 2007 08:32 AM
Sending EMail thru SMTP server in C# - Most of the peri C# 1 December 20th, 2004 09:33 PM
mail() is not sending email on localhost SMTP anshul PHP How-To 5 August 4th, 2004 06:45 AM





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