SirRoshua
asked on
C# contact form code only works offline?
I have a contact us page form written in C# (Code attached), it runs perfectly when testing un-compiled (offline), however, once deployed it fails! Any help would be appreciated.
I have double checked all usernames, passwords and email addresses, but obviously if that was the problem it would not send when testing.
I have double checked all usernames, passwords and email addresses, but obviously if that was the problem it would not send when testing.
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;
using System.Text;
public partial class contact_us : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click(object sender, EventArgs e)
{
try
{
MailMessage EmailMsg = new MailMessage();
EmailMsg.From = new MailAddress("noreply@somwhere.com", " Contact Us");
EmailMsg.To.Add(new MailAddress("EMAIL ADDRESS", "Contact Us"));
EmailMsg.Subject = "Contact Us Page Message";
EmailMsg.Body = "Name: " + txtName.Text + "<br />Email: " + txtEmail.Text + "<br />Comments: " + txtComments.Text;
EmailMsg.IsBodyHtml = true;
EmailMsg.Priority = MailPriority.Normal;
SmtpClient MailClient = new SmtpClient("smtp.1and1.com");
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "noreply@somewhere.com";
NetworkCred.Password = "PASSWORD";
MailClient.Port = 587;
MailClient.Send(EmailMsg);
lblMessage.Text = "Thank you! Your message has been sent successfully. We will respond as soon as possible to your enquiry.";
txtName.Text = "";
txtEmail.Text = "";
txtEmailConfirm.Text = "";
txtComments.Text = "";
}
catch
{
lblMessage.Text = "Sorry! Your message did NOT send. Please check all form field elements and try again.";
}
}
protected void btnClrFrm_Click(object sender, EventArgs e)
{
txtName.Text = "";
txtEmail.Text = "";
txtEmailConfirm.Text = "";
txtComments.Text = "";
lblMessage.Text = "";
}
}
Code block in web.config:
<system.net>
<mailSettings>
<smtp from="noreply@somewhere.com">
<network host="smtp.1and1.com" password="PASSWORD" userName="noreply@somewhere.com" port="587"/>
</smtp>
</mailSettings>
</system.net>
Can you ping smpt.landl.com from the deployment machine? If so, can you telnet to port 25 (or other if server is configured differently) from the same machine?
Also.
What fails? Do you receive any errors, if so, please provide them.
What fails? Do you receive any errors, if so, please provide them.
ASKER
Can ping 1and1.com, however no Telnet capability. 1and1.com is one of the largest hosting companies in the world. If it helps the following comes directly from their site: To send e-mail using the SMTP-Server, activate SMTP Authentication. Please do not use the Secure Password Authentication (SPA) option. Optionally, port 587 can also be used in addition to the default port (25) RFC 2476.
ASKER
Don't know what fails, neither do I see any errors. How would I go about catching it?
I am just getting started in ASP.NET, so the only thing that I can suggest and I am not sure if it will work with .net or not, and that is to make sure that you have show Error Reports to the browser.
(I am a ASP Classic Developer)
IE => Tools | Internet Options | Advanced |
Show friendly HTTP Error messages (Uncheck)
Apply | OK
See if you can see some errors. If not, then maybe one of the others EE's can assist in getting an error if any sent to the browser.
Good Luck
Carrzkiss
(I am a ASP Classic Developer)
IE => Tools | Internet Options | Advanced |
Show friendly HTTP Error messages (Uncheck)
Apply | OK
See if you can see some errors. If not, then maybe one of the others EE's can assist in getting an error if any sent to the browser.
Good Luck
Carrzkiss
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, finally have an error message showing:
Insufficient permissions for setting the configuration property 'port'.
So I removed the port specific syntax from the page and the web.config file, and it worked!!!
Insufficient permissions for setting the configuration property 'port'.
So I removed the port specific syntax from the page and the web.config file, and it worked!!!
ASKER
Although this solution did not actually solve the problem, it did allow me to see what the problem was so I could solve it. But I am not about to award myself points!!
Glad that my asking about the "error" got you where you needed to be at.
Points or no points, glad you have it working.
Good Luck
Carrzkiss
Points or no points, glad you have it working.
Good Luck
Carrzkiss