RichNH
asked on
ASP 4.0 Email ReplyToList build error
Hi all, I am learning ASP and have run into a build error I'm trying to figure out. I am using the WROX book ASP 4.5 as a guide but am running on VS 2010 which I think uses ASP 4.0. Anyway, I have coded up a form which "works" except that if I add the code to add an email address to the ReplyToList of the email message there is a build error. I'm very much a newbie on this and am having trouble resolving the error. The code is in a file named ControlForm.ascx.cs and looks like this:
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_ServerVal idate(obje ct source, ServerValidateEventArgs args)
{
if (!string.IsNullOrEmpty(Pho neHome.Tex t) ||
!string.IsNullOrEmpty(Phon eBusiness. 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 /ContactFo rm.txt");
string mailBody = File.ReadAllText(fileName) ;
mailBody = mailBody.Replace("##Name## ", Name.Text);
mailBody = mailBody.Replace("##Email# #", EmailAddress.Text);
mailBody = mailBody.Replace("##HomePh one##", PhoneHome.Text);
mailBody = mailBody.Replace("##Busine ssPhone##" , PhoneBusiness.Text);
mailBody = mailBody.Replace("##Commen ts##", Comments.Text);
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Response from web site";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("Richard.Zore@ OneSource. com", "Rich at work");
myMessage.To.Add(new MailAddress("Richard.Zore@ onesource. com", "Rich at home"));
myMessage.ReplyToList.Add( new MailAddress(EmailAddress.T ext));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessag e);
Message.Visible = true;
FormTable.Visible = false;
//System.Threading.Thread. Sleep(5000 );
}
}
}
The build error I am getting is this:
Error 1 'System.Net.Mail.MailMessa ge' does not contain a definition for 'ReplyToList' and no extension method 'ReplyToList' accepting a first argument of type 'System.Net.Mail.MailMessa ge' could be found (are you missing a using directive or an assembly reference?) C:\BegASPNET\Site\Controls \ContactFo rm.ascx.cs 44 23 C:\BegASPNET\Site\
As I say, if I comment out the bolded line in the code the error goes away (naturally).
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_ServerVal
{
if (!string.IsNullOrEmpty(Pho
!string.IsNullOrEmpty(Phon
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
protected void SendButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string fileName = Server.MapPath("~/App_Data
string mailBody = File.ReadAllText(fileName)
mailBody = mailBody.Replace("##Name##
mailBody = mailBody.Replace("##Email#
mailBody = mailBody.Replace("##HomePh
mailBody = mailBody.Replace("##Busine
mailBody = mailBody.Replace("##Commen
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Response from web site";
myMessage.Body = mailBody;
myMessage.From = new MailAddress("Richard.Zore@
myMessage.To.Add(new MailAddress("Richard.Zore@
myMessage.ReplyToList.Add(
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessag
Message.Visible = true;
FormTable.Visible = false;
//System.Threading.Thread.
}
}
}
The build error I am getting is this:
Error 1 'System.Net.Mail.MailMessa
As I say, if I comment out the bolded line in the code the error goes away (naturally).
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I did try coding it again but now when I click the send button which should execute the code nothing happens. hey at least it doesn't blow up. But I think that the fact that I am logged into my work PC via VPN might have affected the way some programs work. I know that I found out that there is a lot of security blocking at work and I had to get my name on a list of approved users in order to send emails via code to outside addresses. I'm thinking something may be blocking me from executing code on my work PC from home. They have it screwed down pretty tight.
Anyway, back to the big V.
Rich