protected void ButtonBuy_Click(object sender, EventArgs e)
    {
        //The following statements create a MailMessage object, and add a recipient, sender, message body, and message subject

        //Add a recipient
        string to = TextBoxEmail.Text; // Declare string variable // Value: textbox text

        //Add a sender
        string from = "*****@*****.**"; // Declare string variable // Value: Reelhouse Inc's Gmail

        //Create a System.Net.Mail.MailMessage object
        MailMessage message = new MailMessage(from, to); // Create MailMessage object // Represents SmptClient-sendable e-mail

        //Add a message body
        string mailbody = LabelName.Text + ", " + LabelDOB.Text + ", " + LabelPhoneNo.Text + Environment.NewLine + Environment.NewLine + // Declare string // Label text values // Body text
                          "You have bought a Reelhouse Inc. Ticket for the following: " + Environment.NewLine + Environment.NewLine +    // Body text // String-specific line-breaks
                          LabelMovieTitle.Text + ", " + LabelPrice.Text + ", " + LabelDate.Text + ", " + LabelTime.Text;                 // Label text values

        //Add a message subject
        message.Subject = "Reelhouse Inc. Receipt, " + LabelName.Text + ", " + LabelDate.Text + "."; // Fetch label text

        //Add the message body
        message.Body = mailbody;

        //Create a System.Net.Mail.SmtpClient object
        SmtpClient client = new SmtpClient("smtp.gmail.com", 587);                                                                // Set the SMTP host and port number // 587: Google Mail SMTP

        System.Net.NetworkCredential basicCredential1 = new                                                                       // Create a System.Net.NetworkCredential object
                                                        System.Net.NetworkCredential("*****@*****.**", "cinemaemail123"); // Input Reelhouse Inc's SMTP credentials: Email, Password
        client.EnableSsl             = true;                                                                                      // Enable Secure Socket Layer (SSL) for connection encryption
        client.UseDefaultCredentials = false;                                                                                     // Do not send the DefaultCredentials with requests
        client.Credentials           = basicCredential1;                                                                          // Send Reelhouse Inc's credentials with requests

        //As emails may result in an exception, try is used
        try
        {
            //Send the e-mail
            client.Send(message);
            Response.Redirect("TicketPurchaseConfirm.aspx");
        }
        //Catch e-mail sent errors
        catch (Exception ex)
        {
            //Throw an exception
            //Reset stack trace
            throw ex;
        }
    }
Пример #2
0
    protected void ButtonConfirm_Click(object sender, EventArgs e)
    {
        //The following statements create a MailMessage object, and add a recipient, sender, message body, and message subject

        //Add a recipient
        string to = TextBoxEmail.Text; // Declare string // Value: textbox text

        //Add a sender
        string from = "*****@*****.**"; // Declare string // Value: Reelhouse Inc's Gmail

        //Create a System.Net.Mail.MailMessage object
        MailMessage message = new MailMessage(from, to); // Create MailMessage object // Represents SmptClient-sendable e-mail

        //Add a message body
        string mailbody = "A forgotten password request has been sent to this email. Your password follows:"               // Declare string // Body text
                          + Environment.NewLine + Environment.NewLine +                                                    // String-specific line-breaks
                          "Password: password123" +                                                                        // Body text // Forgotten password // For prototying purposes, password is hard-coded in-line
                          Environment.NewLine + Environment.NewLine +                                                      // String-specific line-breaks
                          "If this email has not been sent by you, please contact Reelhouse Inc.: [email protected]"; // Body text

        //Add a message subject
        message.Subject = "Reelhouse Inc. Forgotten Password.";

        //Add the message body
        message.Body = mailbody;

        //The following statements send ReelHouse Inc's encrypted Gmail credentials
        //over SSL to authenticate and send an email. Consequently, Reelhouse sends built emails.

        //Create a System.Net.Mail.SmtpClient object
        SmtpClient client = new SmtpClient("smtp.gmail.com", 587);                                                                // Set the SMTP host and port number // 587: Google Mail SMTP

        System.Net.NetworkCredential basicCredential1 = new                                                                       // Create a System.Net.NetworkCredential object
                                                        System.Net.NetworkCredential("*****@*****.**", "cinemaemail123"); // Input Reelhouse Inc's SMTP credentials: Email, Password
        client.EnableSsl             = true;                                                                                      // Enable Secure Socket Layer (SSL) for connection encryption
        client.UseDefaultCredentials = false;                                                                                     // Do not send the DefaultCredentials with requests
        client.Credentials           = basicCredential1;                                                                          // Send Reelhouse Inc's credentials with requests

        //Send the e-mail
        client.Send(message);
        //Make label visible
        LabelError.Visible = true; // Informs user email was sent
        //Execute redirect method
        RedirectToLoginAfterXDelay();
    }
Пример #3
0
    protected void ButtonRegister_Click(object sender, EventArgs e)
    {
        //If date of birth is past the present day: Data-validation fails
        if (DateTime.Parse(TextBoxDateOfBirth.Text) > DateTime.Now.Date)
        {
            LabelError.Text = "Error: You must enter a valid date of birth."; // Add label text // Informs user entered date-of-birth's invalid
        }
        //If date of birth was over 100 years ago: Data-validation fails
        else if (DateTime.Parse(TextBoxDateOfBirth.Text) <= DateTime.Now.Date.AddYears(-100))
        {
            LabelError.Text = "Error: You must enter a valid date of birth."; // Add label text // Informs user entered date-of-birth's invalid
        }
        //If date-of-birth data-validation passes:
        else
        {
            //The following statements create a MailMessage object, and add a recipient, sender, message body, and message subject

            //Add a recipient
            string to = TextBoxEmail.Text; // Declare string variable // Value: Textbox text

            //Add a sender
            string from = "*****@*****.**"; // Declare string variable // Value: Reelhouse Inc's Gmail

            //Create a System.Net.Mail.MailMessage object
            MailMessage message = new MailMessage(from, to); // Create MailMessage object // Represents SmptClient-sendable e-mail

            //Add a message body
            string mailbody = "Congratulations! You have succesfully registered with Reelhouse Inc. Your details follow:" // Declare string variable // Body text
                              + Environment.NewLine + Environment.NewLine +                                               // String-specific line-breaks
                              "Forename: " + TextBoxFirstName.Text + Environment.NewLine +                                // Forename // Value: Textbox text // String-specific line-breaks
                              "Surname: " + TextBoxLastName.Text + Environment.NewLine +                                  // Surname // Value: Textbox text // String-specific line-breaks
                              "Date Of Birth: " + TextBoxDateOfBirth.Text + Environment.NewLine +                         // DateOfBirth // Value: Textbox text // String-specific line-breaks
                              "Email Address: " + TextBoxEmail.Text + Environment.NewLine +                               // EmailAddress // Value: Textbox text // String-specific line-breaks
                              "Mobile Phone No.: " + TextBoxMobileNo.Text + Environment.NewLine +                         // MobilePhoneNo. // Value: Textbox text // String-specific line-breaks
                              "Password: "******"We hope you enjoy your membership with Reelhouse Inc.!";                                   // Body text

            //Add a message subject
            message.Subject = TextBoxFirstName.Text + " " + TextBoxLastName.Text + ": You have successfully registered with Reelhouse Inc.";

            //Add the message body
            message.Body = mailbody;

            //Create a System.Net.Mail.SmtpClient object
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);                                                                // Set the SMTP host and port number // 587: Google Mail SMTP
            System.Net.NetworkCredential basicCredential1 = new                                                                       // Create a System.Net.NetworkCredential object
                                                            System.Net.NetworkCredential("*****@*****.**", "cinemaemail123"); // Input Reelhouse Inc's SMTP credentials: Email, Password
            client.EnableSsl             = true;                                                                                      // Enable Secure Socket Layer (SSL) for connection encryption
            client.UseDefaultCredentials = false;                                                                                     // Do not send the DefaultCredentials with requests
            client.Credentials           = basicCredential1;                                                                          // Send Reelhouse Inc's credentials with requests

            //As emails may result in an exception, try is used
            try
            {
                client.Send(message);                                                                                                 // Send the e-email
                LabelError.Text = "Account created! A confirmation email has been sent! Redirecting to the login page in 3, 2, 1..."; // Add label text // Informs user registration proved successful
                //The following statements empty input textboxes
                TextBoxFirstName.Text       = string.Empty;
                TextBoxLastName.Text        = string.Empty;
                TextBoxDateOfBirth.Text     = string.Empty;
                TextBoxMobileNo.Text        = string.Empty;
                TextBoxPassword.Text        = string.Empty;
                TextBoxPasswordConfirm.Text = string.Empty;
                //This statement disables the register button
                //Consequently, users cannot re-register immediately
                //This prevent creating accidental duplicate accounts
                ButtonRegister.Enabled = false;
                //Execute redirect method
                RedirectToLoginAfterXDelay();
            }
            //Catch e-mail sent errors
            catch (Exception ex)
            {
                //Throw an exception
                //Reset stack trace
                throw ex;
            }
        }
    }