Click here to Skip to main content
15,890,995 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to send an email from ASP.Net appliaction??
Please give me sample code for that.
Posted

 
Share this answer
 
No one will give you sample code for your task. have a look there-[send email using asp.net ][^] for plenty of article or codes for getting help.
 
Share this answer
 
Try this,

C#
Using system.net.Mail


ASP.NET
Enter Email :<asp:textbox id="txtEmail" runat="server" xmlns:asp="#unknown"></asp:textbox><br />
<asp:button id="btnSubmit" runat="server" xmlns:asp="#unknown" />


C#
protected void btnSubmit_Click(object sender, EventArgs e)
    {
String strEmail,strFrom,strTo,strSubject,strBody;
           strEmail= txtEmail.Text.ToString();
           strTo = ConfigurationManager.AppSettings["RequestEmail"].ToString();
           strSubject = "News letter subscription";
           strBody = "Email = "+ strEmail.ToString();
           strEmail = Trim(txtEmail.Text);
           MailMessage objmail=new MailMessage();
           objmail.From = strEmail;
           objmail.To.Add(strTo);
           objmail.Subject = strSubject;
           objmail.Body = strBody;
           objmail.IsBodyHtml = True;
           SmtpMail = new SmtpClient(ConfigurationManager.AppSettings["SmtpServer"].ToString()); 
           SmtpMail.Send(objmail);
    }


In web.config,

C#
//Give the ToEmail address .To which you need to send a mail

<add key="RequestEmail" value="test@maildomain.com" />
//Give the server(domain name) in value

<add key="SmtpServer" value="Smptp server name" />


Hope it helps..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900