Subject: Chapter 7 Email setting for "forgot password?"
Posted By: hdpark Post Date: 11/23/2007 2:28:08 PM
Hi experts,

I am testing Chapter 7 sample program.
How can I set up email send/receive for "Login>forgot passowrd?"?
My personal email address is hyungdoo@gmail.com. So I put it to Chapter 7 sample program's web.config as follows. But it doesn't work.
Your kind advice would be appreciated.

Thanks,

====web.config========

.
.
?lt;appSettings>
    <add key="EmailFrom" value="hyungdoo@gmail.com" />
    <add key="EmailTo" value="hyungdoo@gmail.com" />
    <add key="PageTitle" value="Wrox Photo Album"/>
    ?lt;add key="CurrentTheme" value="cleanred" />
?lt;/appSettings>
.
.
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="smtp.gmail.com" port="25" />
      </smtp>
    </mailSettings>
  </system.net>

Reply By: Imar Reply Date: 11/23/2007 3:34:58 PM
Hi there,

Can you define "doesn't work"? Do you get an error? If so, what error do you get?

Also, I don't think you can use Google's mail server like that without putting a  username and password in the <network /> element.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply By: hdpark Reply Date: 11/26/2007 11:04:37 AM
Hi Imar,

Thanks for your advice.

1. If I add my username and password like follows, I have follwing error messages.
   <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="smtp.gmail.com" userName="hyungdoo" password="mypassword" port="25" />
      </smtp>
    </mailSettings>

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

A from e-mail address must be specified in the From property or the system.net/mailSettings/smtp config section.
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.Web.HttpException: A from e-mail address must be specified in the From property or the system.net/mailSettings/smtp config section.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[HttpException (0x80004005): A from e-mail address must be specified in the From property or the system.net/mailSettings/smtp config section.]
   System.Web.UI.WebControls.MailDefinition.CreateMailMessage(String recipients, IDictionary replacements, String body, Control owner) +1411614
   System.Web.UI.WebControls.LoginUtil.CreateMailMessage(String email, String userName, String password, MailDefinition mailDefinition, String defaultBody, Control owner) +183
   System.Web.UI.WebControls.LoginUtil.SendPasswordMail(String email, String userName, String password, MailDefinition mailDefinition, String defaultSubject, String defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner) +341
   System.Web.UI.WebControls.PasswordRecovery.AttemptSendPasswordQuestionView() +653
   System.Web.UI.WebControls.PasswordRecovery.AttemptSendPassword() +66
   System.Web.UI.WebControls.PasswordRecovery.OnBubbleEvent(Object source, EventArgs e) +101
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

2. If I change it like this:
      <mailSettings>
          <smtp from="hyungdoo@gmail.com">
              <network host="smtp.gmail.com" userName="hyungdoo" password="my password" port="25" />
          </smtp>
      </mailSettings>

Then I have follwoing messages:

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 u2sm991187pyb
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 u2sm991187pyb

3. If I change it like this:
      <mailSettings>
          <smtp from="postmaster@myhostingname.net">
              <network host="smtp.myhostingname.net" userName="myusername" password="mypassword" port="25" />
          </smtp>
      </mailSettings>

Then I have two kinds of results:
1) If the username's email address is in this hosting site, it's good to send out.
2) If the username 's email address is not in this hosting site, it's not. The error message from here is:

Mailbox unavailable. The server response was: <sungsook.park@gmail.com> No such user here
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.SmtpFailedRecipientException: Mailbox unavailable. The server response was: <sungsook.park@gmail.com> No such user here

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


I hope these several status will be helpful to you.

Thanks,

          

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1378; ASP.NET Version:2.0.50727.1378

Reply By: Imar Reply Date: 11/26/2007 11:28:01 AM
For the SSL error, you need to set the EnableSsl property on the SmtpClient instance like this:

smtpClient.EnableSsl = true


Hope this helps,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply By: hdpark Reply Date: 11/29/2007 4:45:12 PM
Hi Imar,

I did it successfully in Chapter 6 like this:
<mailSettings>
 <smtp from="myname@myhostingsite.com">
  <network host="localhost" userName="" password="" port="25" />
 </smtp>
</mailSettings>

Thanks for your kind help.


Reply By: Imar Reply Date: 11/29/2007 5:28:38 PM
Great. You're welcome....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply By: Jamessaep Reply Date: 4/1/2008 11:33:40 AM
Using The Beer House Contact.aspx page, How would I enableSsl in the code-behind:

      protected void btnSubmit_Click(object sender, EventArgs e)
      {
         try
         {
            // send the mail
            MailMessage msg = new MailMessage();
            msg.IsBodyHtml = false;
            msg.From = new MailAddress(txtEmail.Text, txtName.Text);
            msg.To.Add(new MailAddress(Globals.Settings.ContactForm.MailTo));
            if (!string.IsNullOrEmpty(Globals.Settings.ContactForm.MailCC))
               msg.CC.Add(new MailAddress(Globals.Settings.ContactForm.MailCC));
            msg.Subject = string.Format(Globals.Settings.ContactForm.MailSubject, txtSubject.Text);
            msg.Body = txtBody.Text;
            new SmtpClient().Send(msg);
            
            // show a confirmation message, and reset the fields
            lblFeedbackOK.Visible = true;
            lblFeedbackKO.Visible = false;
            txtName.Text = "";
            txtEmail.Text = "";
            txtSubject.Text = "";
            txtBody.Text = "";
         }
         catch (Exception)
         {
            lblFeedbackOK.Visible = false;
            lblFeedbackKO.Visible = true;
         }
      }



quote:
Originally posted by Imar

For the SSL error, you need to set the EnableSsl property on the SmtpClient instance like this:

smtpClient.EnableSsl = true


Hope this helps,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004



Reply By: Imar Reply Date: 4/1/2008 11:58:56 AM
Hi James,

How is the Beer house related to this?

Anyway, is my previous example not enough to get you started? You need to set EnableSsl to true. In your case, you create an instance of SmtpClient and call Send in one line, so you need to split that:

SmtpClient myClient = new SmtpClient()
myClient.EnableSsl = true;
myClient.Send(msg);

Cheers and hope this helps,

Imar



---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply By: Jamessaep Reply Date: 4/1/2008 12:42:27 PM
Thanks for the reply. I have another post at http://p2p.wrox.com/topic.asp?TOPIC_ID=70246 which has the settings you specided, but with those settings, I have a problem. Could you look at my other thread and see if you have a solution?

Reply By: mrcarte2 Reply Date: 4/23/2008 2:40:41 PM
along with [hdpark's] post :
"2. If I change it like this:
      <mailSettings>
          <smtp from="hyungdoo@gmail.com">
              <network host="smtp.gmail.com" userName="hyungdoo" password="my password" port="25" />
          </smtp>
      </mailSettings>

Then I have follwoing messages:

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 u2sm991187pyb
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. "

has there been a way to fix this ?  or what do we need to insert to make this work .. localhost on port 25 works but im not going to be the one hosting this so i dont want people connecting to me computer..

Reply By: Imar Reply Date: 4/23/2008 2:48:53 PM
Yes, the fix is in an earlier post:

smtpClient.EnableSsl = true

Unfortunately, you cannot set this in web.config, so you need to do this programmatically. For .NET triggered e-mail (forgotten password and so on) this won't work, so you'll need to write your own mail sending code for that.

As an alternative, find an ISP / SMTP server that doesn't require SSL.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

Go to topic 70824

Return to index page 1