asp:passwordrecovery enable a user to recoverOrReset a lost password and receive mail

Discussion in 'Site Programming, Development and Design' started by l3ny, Nov 1, 2009.

  1. Hi, Ive being trying for weeks w/out success, I have a passwordrecovery control on the page, i have on the web.config:

    <system.net>
    <mailSettings>
    <smtp from="postmaster@site.com">
    <network host="mail.site.com" password="blabla" port="25" userName="postmaster@site.com"/>
    </smtp>
    </mailSettings>
    </system.net>

    and nothing, then i tried;

    void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
    {
    e.Message.IsBodyHtml = false;
    e.Message.Subject = "New password on Web site.";

    <asp:passwordrecovery id="PasswordRecovery1" runat="server" onsendingmail="PasswordRecovery1_SendingMail" >
    </asp:passwordrecovery>

    ps.
    i also have the trust on web.config; <trust level="Full" originUrl="" />

    and still nothing, has anyone done it succesfuly?
    I get this error:
    System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: <correctUser@mail.com> No such user here

    the email is from the db which is correct.

    Hope someone can help.
    Thank you in advance..

    ~l3ny
     
  2. I've managed to get it to work. Here's my code to send:

    C#:
    using System.Net.Mail;

    MailMessage newMail = new MailMessage("FROM ADDRESS", "TOADDRESS", "SUBJECT", "BODY");
    SmtpClient SmtpSender = new SmtpClient();
    SmtpSender.Port = 25;
    SmtpSender.Host = "mail.YOURDOMAIN.com";
    SmtpSender.Send(newMail);

    Web.Config:

    <system.net>
    <mailSettings>
    <smtp>
    <network defaultCredentials="false" host="mail.YOURDOMAIN.com" port="25" userName="UserName@YourDomain.com" password="PW" />
    </smtp>
    </mailSettings>
    </system.net>
     
  3. Alternately, if you're like me and are pretty lazy, you could dump this into your App_Code (file name is QuickEmail.cs):

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Net.Mail;

    /// <summary>
    /// This is an easy email script that will send emails without declaring a bunch of objects on the page.
    /// </summary>
    public class QuickEmail
    {
    public QuickEmail(bool html, string Fromname, string from, string to, string subject, string body)
    {
    MailMessage newMail = new MailMessage();
    newMail.To.Add(to);
    newMail.Subject = subject;
    newMail.Body = body;
    newMail.From = new MailAddress(from, Fromname);
    newMail.IsBodyHtml = html;
    SmtpClient SmtpSender = new SmtpClient();
    SmtpSender.Port = 25;
    SmtpSender.Host = "mail.qbtournaments.com";
    SmtpSender.Send(newMail);
    }
    }


    This would let you send emails like this on individual pages:

    string body = "This would be the first line of your HTML message<br/>";
    body += "This would be the second line.";
    QuickEmail email = new QuickEmail(true,"FROM DISPLAY NAME",FromEmailAddress@DOMAIN.COM","TOEMAILADDRESS","SUBJECT",body);

    The parameters are, in order:
    boolean IsBodyHTML: true/false - will declare the email to be HTML.
    string Fromname: display name the recipient will see
    string from: email address this message will be sent from
    string to: email address the message will be sent to
    string subject: subject of the email
    string body: body of the email.

    You could switch the declared strings for variables. I'll be happy to help you if you have any questions about this. Basically you just create a single object of the type QuickEmail and it'll automatically send it for you. It's just a simplified approach to sending email, I think.
     
  4. re: reagan

    Thanks Daegan, here is the report.
    The following code works for example on the Create User page(AKA register) Side effects: it will send you 2 email from the page it self ("cause it doesn't like any other email-only an admin email) + the 1 from the web.config file i guess. because I'm getting 3 email.

    //MailMessage newMail = new MailMessage("FROM ADDRESS", "TOADDRESS", "SUBJECT", "BODY");
    MailMessage newMail = new MailMessage("postmaster@site.com", "postmaster@site.com", "New Subscription", "Hi you have a new Customer");
    SmtpClient SmtpSender = new SmtpClient();
    SmtpSender.Port = 25;
    SmtpSender.Host = "mail.site.com";
    SmtpSender.Send(newMail);

    The password recovery email does not work.-it says that the email is not correct (a real correct user email) i just doesn't like other email this server.

    The contact form- smtp.Send(mail); just sends you to gray list :)

    If some one can share with me a working form i will appreciate it. it is not laziness on my part. here are my testing pages.
    http://www.site.com/delete.aspx and http://www.site.com/ForgotPassword.aspx user: test

    my code for contact form:
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void SendMail(object sender, EventArgs e)
    {
    if (!IsValid)
    {
    return;
    }
    else
    {
    MailMessage mail = new MailMessage();
    mail.From = new MailAddress(EmailTB.Text); // mail.From = new System.Net.Mail.MailAddress(EmailTB.Text);
    mail.To.Add("postmaster@site.com");
    mail.Subject = "SomeOne Needs your help";
    mail.IsBodyHtml = true;
    mail.Body = "First Name: " + FNameTB.Text + "<br />";
    mail.Body += "Last Name: " + LNameTB.Text + "<br />";
    mail.Body += "Email: " + EmailTB.Text + "<br />";
    mail.Body += "Comments: " + CommentsTB.Text + "<br />";

    SmtpClient smtp = new SmtpClient();
    smtp.Host = "mail.site.com";
    smtp.Send(mail);
    }
    }
    protected void Reset(object s, EventArgs e)
    {
    FNameTB.Text = "";
    LNameTB.Text = "";
    EmailTB.Text = "";
    CommentsTB.Text = "";
    }

    Thanks.
     
  5. I don't see why it's emailing you twice. I have this working just find on my website.

    Is the event that triggers the email being called multiple times?

    Here's my exact code to email, and it's working as a contact form. I assume it'd work for the recovery system too, but i've not tried it.


    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Net.Mail;
    
    public partial class contactform : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Send(object sender, EventArgs e)
        {
            MailMessage newMail = new MailMessage();
            newMail.To.Add("ToEmailAddress");
            newMail.Subject = SubjectTB.Text;
            newMail.Body = BodyTB.Text.Replace("\n","<br/>");
            newMail.From = new MailAddress(FromTB.Text, NameTB.Text);
            newMail.IsBodyHtml = true;
            SmtpClient SmtpSender = new SmtpClient();
            SmtpSender.Port = 25;
            SmtpSender.Host = "mail.yourdomain.com";
            SmtpSender.Send(newMail);
            Response.Redirect("THANKYOUPAGE.ASPX");
        }
    }
    
    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="contactform.aspx.cs" Inherits="contactform" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <dl>
                <dt>Your Name</dt>
                <dd><asp:TextBox runat="server" ID="NameTB" /></dd>
                <dt>Your E-Mail Address</dt>
                <dd><asp:TextBox runat="server" ID="FromTB" /></dd>
                <dt>Subject</dt>
                <dd><asp:TextBox runat="server" ID="SubjectTB" /></dd>
                <dt>Body</dt>
                <dd>
                    <asp:TextBox runat="server" TextMode="MultiLine" ID="BodyTB" />
                </dd>
                <dt></dt>
                <dd><asp:Button runat="server" ID="SendEmailBtn" OnClick="Send" Text="Send" /></dd>
                
            </dl>
            
            
        </div>
        </form>
    </body>
    </html>
    
    I have this right before the </configuration> tag in my web.config.
    Code:
    	<system.net>
    		<mailSettings>
    			<smtp>
    				<network defaultCredentials="false" host="mail.DOMAIN.com" port="25" userName="USERNAME@DOMAIN.com" password="PASSWORD"/>
    			</smtp>
    		</mailSettings>
    	</system.net>
    
    
     
  6. re: reagan

    If i use postmaster@site.com = Error in processing. The server response was: Greylisted, please try again in 900 seconds
    if i use l3ny@ msn no sus user here.

    I use the your exact sample (C attached), may it be that there is something not set in my account with Winhost?
    http://www.xn--aespaol-8za.com/delete2.aspx
     

    Attached Files:

    Last edited by a moderator: Oct 14, 2015
  7. i think you must catch if the event is a postback. that's probably the reason why you receive 2 mails.
     
  8. I don't use postmaster to send my messages. I setup a different account that was an administrator and send email through it. This is absolutely the only difference that I can see between our code.

    I'd try to do that, since you're using all of my code, and I assume that you have the web.config setup properly.
     
  9. Ray

    Ray

    All our email accounts by default have greylisting features enabled. That is probably why you are getting this error message.

    The server response was: Greylisted, please try again in 900 seconds

    This bounce back/error message does not mean that the email will be permenantly rejected but temporarily delayed and the server will try again to send it at the predefined time.

    Greylisting is a feature that greatly reduces the number of spam you get in your inbox. The way it works is that it sends a temporary rejection code "within the 400 range", and this tells the sending party to try again later. The second attempt to send it will accept it.

    Beaware that the downside of the greylisting feature is that legitimate emails tend to arrive late. If the emails you are sending into is an email account we host then you should be able to disable the greylist feature of this pop account from within the webmail interface under Settings. If this email is hosted by some other hosting service you may want to contact them and inquire if there is a way to bypass greylisting.

    Our email accounts also has a whitelist feature so if you input the domain name on the whitelist it will not go through greylisting. But again that is only for our email system and I cannot speak for other hosting providers setup.
     
  10. Ray

    Ray

    Make sure you are passing smtp authetnication on your code. That means you need to log into the smtp server first before the smtp server sends out the email.
     
  11. re ray

    I added l3ny@msn.com as trusted, and now works.....if i put it as from: however don't work with others this is driving me crazy...

    smtp its working remember the 3 from the the sign up page i move the code to the complete wizard(2d button template) n now send 1.

    so credential n smtp work.
     
  12. Ray

    Ray

    I still don't think you are passing the correct authentication to the smtp server. I made some modification on one of the example code you posted. Try looking to it and make the adjustment on your code.

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

    public partial class contactform : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Send(object sender, EventArgs e)
    {
    MailMessage newMail = new MailMessage();
    newMail.To.Add("ToEmailAddress");
    newMail.Subject = SubjectTB.Text;
    newMail.Body = BodyTB.Text.Replace("\n","<br/>");
    newMail.From = new MailAddress(FromTB.Text, NameTB.Text);
    newMail.IsBodyHtml = true;
    SmtpClient SmtpSender = new SmtpClient();



    Dim SmtpSender As New SmtpClient
    Dim basicAuthenticationInfo As New System.Net.NetworkCredential("postmaster@yourdoamin.com", "password")


    SmtpSender.Host = "mail.yourdomain.com";
    SmtpSender.Port = 25;

    SmtpSender.UseDefaultCredentials = False
    SmtpSender.Credentials = basicAuthenticationInfo
    SmtpSender.Send(newMail);
    Response.Redirect("THANKYOUPAGE.ASPX");

    }
    }
     
  13. Thanks ray, I change the password and disable the graylist option inside mail set up. now works. it was incorrect authentication.
     

Share This Page