Forum Moderators: open
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Net.Mail" %>
<script language="C#" runat="server">
string MailFrom, MailTo = "";
void Button_Click(Object sender, EventArgs e)
{
MailFrom = ContactEmail.Text;
MailTo = "a@b.com";
MailMessage Email = new MailMessage(MailFrom, MailTo);
Email.Subject = "Website Comments";
// Not sure if I need this, am adding it cause I want line breaks in the e-mail message I get.
//
// Email.IsBodyHtml = true;
// Need help with the body, I want to be able to place the First Name and the Last name from
// my form in the e-mail message, as well as the comments user added.
//
// Email.Body
// Trying to add the credentials here, domain will not accept. should I add them in web.config?
// If yes, I am not sure how to do that, please help.
//
// SmtpClient client = new SmtpClient();
// client.Credentials = CredentialCache.DefaultNetworkCredentials;
// client.Send(Email);
}
</script>
<form method="post" runat="server">
<p>
Name:<br />
<asp:TextBox ID="ContactName" Columns="50" runat="server" />
</p>
<p>
E-Mail Address:<br />
<asp:TextBox ID="ContactEmail" Columns="50" runat="server" />
<asp:RegularExpressionValidator ControlToValidate="ContactEmail" Text="Invalid Email Address!" ValidationExpression="\S+@\S+\.\S{2,3}" runat="Server" />
</p>
<p>
Comments:<br />
<asp:TextBox ID="EmailBody" TextMode="MultiLine" Columns="75" Height="150px" Text="Please enter comments." runat="server" />
</p>
<p>
<asp:Button Text="Send" OnClick="Button_Click" runat="server" />
</p>
</form>
"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"
As far as I can track it, my e-mail credentials are not correct and my SMTP host is not letting me log in with the user name and password.
Is there a better way to pass this info to the smtp client?