How to Send Bulk Email in Asp.net with Example using C#

Category > ASP.NET || Published on : Sunday, July 6, 2014 || Views: 19079 || Asp.net C#.Net SendMail VB.NET


In this article, I'm explaining how to send bulk email using ASP.NET and C#. The prerequisite to send bulk email we need list of Email Id's, whom we want to send emails.

 


Steps 1: Create a new web application and add a new html page, This html will be send as Email body

create-console-application



create-console-application

 

 

 

 

 

 

"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
"http://www.w3.org/1999/xhtml">

    HTML Template


UserName:$$UserName$$ PassWord: $$Password$$ Thanks

 


Step 2: Now in your Default.aspx page write the following code

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Net.Mail;
namespace BulkEmail
{
    public partial class Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
        {
            BindGridviewData();
        }
    protected void BindGridviewData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("UserName", typeof(Int32));
            dt.Columns.Add("Password", typeof(string));
            dt.Rows.Add(1, "Raju", "raju@gmail.com");
            dt.Rows.Add(2, "Shyam", "shyam@gmail.com");
            dt.Rows.Add(3, "Laxman", "laxman@gmail.com");
            dt.Rows.Add(4, "kumar", "kumar@hotmail.com");
            gvDetails.DataSource = dt;
            gvDetails.DataBind();
        }
    protected void btnSend_Click(object sender, EventArgs e)
        {
    foreach (GridViewRow grow in gvDetails.Rows)
            {
    string strContactName = grow.Cells[1].Text.Trim();
    string strEmail = grow.Cells[2].Text.Trim();
                StreamReader reader = new StreamReader(Server.MapPath("~/Email.html"));
    string readFile = reader.ReadToEnd();
    string myString = readFile;
                myString = myString.Replace("$$UserName$$", strCon
                        

Download Source Codes