tatton777
04-07-2006, 03:02 AM
I've got threepages on my website that send email, two are working great. The third isn't. I cut and past the code from the first example that works, as a model for the second, that doesn't send me an email. Can anyone spot where I'm goofing up. If it makes a difference, the first set of code is in a Page_Load() event, the second is in a Button_Click() event. I've include System.Net.Mail in both classes, just so we can get that out of the way.
First Set of Code that works:
try
{
string zBody = "User:" + zEmail + " Password:" + zPassword;
MailMessage mailMessage = new MailMessage(postmaster@myschoolfees.com,
zEmail, "Your MySchoolFees Password", zBody);
SmtpClient client = new SmtpClient("localhost");
client.Send(mailMessage);
MailStatusLabel.Visible = true;
MailStatusLabel.Text = "Your password has been sent to " + zEmail;
}
catch (Exception ex)
{
MailStatusLabel.Visible = true;
MailStatusLabel.Text = "Failed to send message!! Error: " + ex.Message;
}
Second set of code that doesn't return an error, but I don't get an email:
string zFrom = txtUserName.Text;
string zTo = "validemailaddress@email.com";
string zSubject = "Request for Security Level Upgrade";
try
{
string zBody = "REQUEST FOR SECRETARIAL SECURITY LEVEL UPGRADE : UserName: " +
txtUserName.Text + " SchoolID: " + txtSchoolID.Text ;
MailMessage mailMessage = new MailMessage(zFrom, zTo, zSubject, zBody);
SmtpClient client = new SmtpClient("localhost");
client.Send(mailMessage);
MessageLabel.Visible = true;
MessageLabel.Text = "Your request has been sent. You will receive a response " +
"within 24 hours. PLEASE: Close this window to continue.";
}
catch (Exception ex)
{
MessageLabel.Visible = true;
MessageLabel.Text = "Failed to send message!! Error: " + ex.Message + "." +
"Please contact tech support at ***-***-****. " +
"PLEASE: Close this window to continue.";
}
First Set of Code that works:
try
{
string zBody = "User:" + zEmail + " Password:" + zPassword;
MailMessage mailMessage = new MailMessage(postmaster@myschoolfees.com,
zEmail, "Your MySchoolFees Password", zBody);
SmtpClient client = new SmtpClient("localhost");
client.Send(mailMessage);
MailStatusLabel.Visible = true;
MailStatusLabel.Text = "Your password has been sent to " + zEmail;
}
catch (Exception ex)
{
MailStatusLabel.Visible = true;
MailStatusLabel.Text = "Failed to send message!! Error: " + ex.Message;
}
Second set of code that doesn't return an error, but I don't get an email:
string zFrom = txtUserName.Text;
string zTo = "validemailaddress@email.com";
string zSubject = "Request for Security Level Upgrade";
try
{
string zBody = "REQUEST FOR SECRETARIAL SECURITY LEVEL UPGRADE : UserName: " +
txtUserName.Text + " SchoolID: " + txtSchoolID.Text ;
MailMessage mailMessage = new MailMessage(zFrom, zTo, zSubject, zBody);
SmtpClient client = new SmtpClient("localhost");
client.Send(mailMessage);
MessageLabel.Visible = true;
MessageLabel.Text = "Your request has been sent. You will receive a response " +
"within 24 hours. PLEASE: Close this window to continue.";
}
catch (Exception ex)
{
MessageLabel.Visible = true;
MessageLabel.Text = "Failed to send message!! Error: " + ex.Message + "." +
"Please contact tech support at ***-***-****. " +
"PLEASE: Close this window to continue.";
}