How to Send E-mails in c#

Total Post:341

C#  ASP.Net 
 1050  View(s)
Rate this:
I want to send Mail in c# how to write code in c# please help me.
  1. Post:281

    Re: How to Send E-mails in c#

    Sending e-mails with ASP.NET is pretty straight forward. The .NET framework comes with an entire namespace for handling e-mails, the System.Net.Mail namespace. In the following examples, we will use two classes from this namespace: The MailMessage class, for the actual e-mail, and the SmtpClient class, for sending the e-mail.
    As you may be aware, mails are sent through an SMTP server, and to send mails with the .NET framework, you will need access to an SMTP server. If you're testing things locally, the company that supplies your with Internet access, will usually have an SMTP server that you can use, and if you wish to use one of these examples on your actual website, the company that hosts your website will usually have an SMTP server that you can use. Go through the support pages to find the actual address - it's usually something along the lines of or
    Once you have an accessible SMTP server, we're ready to send our very first e-mail using Gmail SMTP. For the first example, all you need is an empty page, with the following code in the CodeBehind button click:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Net;

    using System.Net.Mail;

    using System.Web;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    namespace Forumasp



    public partial class sendmail : System.Web.UI.Page


    protected void Page_Load(object sender, EventArgs e)



    protected void Button1_Click(object sender, EventArgs e)


    using (MailMessage Mail = new MailMessage("",""))


    Mail.Subject = "Request";

    Mail.Body = "hello";

    Mail.IsBodyHtml = false;

    SmtpClient smtp = new SmtpClient();

    smtp.Host = "";

    smtp.EnableSsl = true;

    NetworkCredential NetworkCred = new NetworkCredential("", "XXXXXXX");

    smtp.UseDefaultCredentials = true;

    smtp.Credentials = NetworkCred;

    smtp.Port = 587;


    ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);






      Modified On Apr-10-2018 05:41:39 AM