shubhranshuaki 0 Newbie Poster

hello Friends...

I am trying to send email on button click and i did it sucessfully...

but now i am try to autorespond of same mail.. here i will define my problem..

my aspx page code:-

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TxtEmail" runat="server"></asp:TextBox>
    <asp:Button runat="server" Text="Submit" ID="BtnEmail" onclick="BtnEmail_Click"/>
    </div>
    </form>
</body>
</html>

And my aspx.cs page code:-

protected void BtnEmail_Click(object sender, EventArgs e)
    {
        

 MailMessage mail = new MailMessage();
 

        mail.To.Add("name@mydomain.com");


        mail.From = new MailAddress("name@mydomain.com");


        
        mail.Subject ="Test";

        mail.IsBodyHtml = true;
        mail.Body = "<div><span style = 'margin:left:10px'><b>Subscribe NewsLetter to <b>" + TxtEmail.Text.Trim() +"</span></div>";

SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp1.mail.pw";
        smtp.Credentials = new System.Net.NetworkCredentia("name@mydomain.com","xyzqwe");
        smtp.Send(mail);

}

From these codes i can sent mail..

but now i need to create auto reply to subimmited email id i.e <asp:TextBox ID="TxtEmail" runat="server"></asp:TextBox>.. Requester submit his/her email id here.. i will get the mail for newsletter subscription and requester will have to recieve one confirmation mail too form my id...

i tried one code for this but didnt do it.. example of that code is same..

ex:-

protected void BtnEmail_Click(object sender, EventArgs e)
    {
        

 MailMessage mail = new MailMessage();
 string Request = "Request";

        mail.To.Add("name@mydomain.com");


        mail.From = new MailAddress("name@mydomain.com");


      
        mail.Subject ="Test";

        mail.IsBodyHtml = true;
        mail.Body = Request;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp1.mail.pw";
        smtp.Credentials = new System.Net.NetworkCredential("name@mydomain.com","xyzqwe");
        smtp.Send(mail);

        


MailMessage mail1 = new MailMessage();
string Reply = "TEST COMPLITE";
        mail1.To.Add("TxtEmail.Text");
        
        mail1.From = new MailAddress("name@mydomain.com");
        mail1.Subject = "TestAccomplish";
        mail1.IsBodyHtml = true;
        mail.Body = Reply;
        SmtpClient smtp1 = new SmtpClient();
        smtp1.Host = "smtp1.mail.pw";
        smtp1.Credentials = new System.Net.NetworkCredential("name@mydomain.com", "xyzqwe");
        smtp1.Send(mail);
    }

it shows me error that mail1.to.add does not accept string.. so help me how can i do this ..

and please don tell meto use database beacuse i am not using database for this project...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.