I have a 4pg process and the 3rd page is my confirmation page. This page has a button which sends and email. Then once the email has been sent or not, I have a response.redirect. What I want to do though is if the email has been sent then go to next page but if it fails to send, then display and error on the page and not redirect.
Not to sure how to do this. My code for the is
protected void pg3button_Click(object sender, EventArgs e)
{
try
{
//Create the msg object to be sent
MailMessage msg = new MailMessage();
//Add your email address to the recipients
msg.To.Add("test@test.com");
//Configure the address we are sending the mail from
MailAddress address = new MailAddress("test@test.com");
msg.From = address;
//Append their name in the beginning of the subject
msg.Subject = "Enquiry";
msg.Body = Label1.Text + " " + Session["pg1input"].ToString()
+ Environment.NewLine.ToString() +
Label2.Text + " " + Session["pg1dd"].ToString()
+ Environment.NewLine.ToString() +
Label3.Text + " " + Session["pg2"].ToString();
//Configure an SmtpClient to send the mail.
SmtpClient client = new SmtpClient("smtp.live.com", 587);
client.EnableSsl = true; //only enable this if your provider requires it
//Setup credentials to login to our sender email address ("UserName", "Password")
NetworkCredential credentials = new NetworkCredential("test@test.com", "Password");
client.Credentials = credentials;
//Send the msg
client.Send(msg);
//Display some feedback to the user to let them know it was sent
lblResult.Text = "Your message was sent!";
//Clear the form
//txtName.Text = "";
//txtMessage.Text = "";
}
catch
{
//If the message failed at some point, let the user know
lblResult.Text = "Your message failed to send, please try again.";
}
Response.Redirect("/Session/Pg4.aspx");
}
Aucun commentaire:
Enregistrer un commentaire