yep, you're right. of course. who am i to think you might be wrong??
I AM IN THE WRONG FORUM. I have the ASP.NET 4 version.
Anywho...
I've clicked around the correct forum and followed a few of your threads but still I haven't been able to figure out what I'm doing wrong. I haven not launched the page I am only using the local VWD debug mode. Here's my code.
ContactForm.ascx.cs
Quote:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO; // Provides access to the File class for reading the file
using System.Net.Mail; // Provides access to the various mail related classes
public partial class Controls_ContactForm : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (!string.IsNullOrEmpty(PhoneHome.Text) || !string.IsNullOrEmpty(PhoneBusiness.Text))
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
protected void SendButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string fileName = Server.MapPath("~/App_Data/ContactForm.txt");
string mailBody = File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", Name.Text);
mailBody = mailBody.Replace("##Email##", EmailAddress.Text);
mailBody = mailBody.Replace("##HomePhone##", PhoneHome.Text);
mailBody = mailBody.Replace("##BusinessPhone##", PhoneBusiness.Text);
mailBody = mailBody.Replace("##Comments##", Comments.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Response from web site";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("[email protected]", "Sender Name");
myMessage.To.Add(new MailAddress("[email protected]", "Receiver Name"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
Message.Visible = true;
FormTable.Visible = false;
}
}
}
|
Web.config
Quote:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<pages theme="Monochrome">
<controls>
<add tagPrefix="Wrox" tagName="Banner" src="~/Controls/Banner.ascx"/>
</controls>
</pages>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<appSettings>
<add key="MyEmailAddr" value="[email protected]"/>
<add key="ToEmailAddr" value="[email protected]"/>
<add key="EmailHost" value="smtp.gmail.com"/>
<add key="FromEmailAddr" value="[email protected]"/>
</appSettings>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="[email protected]">
<network enableSsl="true"
port="587"
userName="[email protected]"
password="MYPASSWORD"
host="smtp.gmail.com"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
|
thank you sir!