Link to home
Create AccountLog in
Avatar of RichNH
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_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("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.Text));
            SmtpClient mySmtpClient = new SmtpClient();
            mySmtpClient.Send(myMessage);
            Message.Visible = true;
            FormTable.Visible = false;
            //System.Threading.Thread.Sleep(5000);
        }
    }
}

The build error I am getting is this:
Error      1      'System.Net.Mail.MailMessage' does not contain a definition for 'ReplyToList' and no extension method 'ReplyToList' accepting a first argument of type 'System.Net.Mail.MailMessage' could be found (are you missing a using directive or an assembly reference?)      C:\BegASPNET\Site\Controls\ContactForm.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).
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of RichNH
RichNH

ASKER

Sorry it has been some long.  I do see the method in the list.  It has been very busy at work and I haven't been able to attend to this for some time.  I am on vacation for the coming week but anticipate that I will be able to look into this the following week.  I do appreciate your reply, There just aren't enough hours in the day.

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