I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
If you want to send email in bulk then you should go for my algorithm. I have already learn about SMTP services (how to to send e-mail). Today we will learn , how to send email in bulk. There are various steps to send email in bulk, these are
1. Bind proper information of customer in gridview (learn how to bind gridview in asp.net)
2. Make user friendly application, in which you can insert data in gridview at runtime.(How to insert data into database)
3. Take two textboxes on design window for email-subject and email-message.
4. Also add single button control for sending message.
5. Raise click_event for button control.
6. Run foreach loop for all rows of gridview like
foreach (GridViewRow gdata in GridView1 .Rows)
{
}
7. Extract e-mail field from gridview, now, your code look like.
string email = gdata.Cells[3].Text.Trim();
8. After retrieving single address from gridview, now you can send message.
9. Run your application.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Net.Mail;
public partial class daclass : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString =ConfigurationManager.ConnectionStrings ["ConnectionString"].ToString();
con.Open();
SqlCommand cmd=new SqlCommand ();
cmd.CommandText ="select * from [user]";
cmd.Connection =con;
SqlDataAdapter da=new SqlDataAdapter (cmd);
DataSet ds=new DataSet();
da.Fill (ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow gdata in GridView1 .Rows)
{
string email = gdata.Cells[3].Text.Trim();
MailMessage msg = new MailMessage();
msg.From = new MailAddress("your gmail id here");
msg.To.Add(email);
msg.Subject = TextBox1.Text;
msg.Body = TextBox2.Text;
msg.IsBodyHtml = true;
SmtpClient smt = new SmtpClient("smtp.gmail.com", 587);
smt.EnableSsl = true;
smt.Credentials = new System.Net.NetworkCredential("your gmail id here", "your gmail password");
smt.Send(msg);
Response.Write("message send");
}
}
}
Code Generate the following output
1. Bind proper information of customer in gridview (learn how to bind gridview in asp.net)
2. Make user friendly application, in which you can insert data in gridview at runtime.(How to insert data into database)
3. Take two textboxes on design window for email-subject and email-message.
4. Also add single button control for sending message.
5. Raise click_event for button control.
6. Run foreach loop for all rows of gridview like
foreach (GridViewRow gdata in GridView1 .Rows)
{
}
7. Extract e-mail field from gridview, now, your code look like.
string email = gdata.Cells[3].Text.Trim();
8. After retrieving single address from gridview, now you can send message.
9. Run your application.
Complete code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Net.Mail;
public partial class daclass : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString =ConfigurationManager.ConnectionStrings ["ConnectionString"].ToString();
con.Open();
SqlCommand cmd=new SqlCommand ();
cmd.CommandText ="select * from [user]";
cmd.Connection =con;
SqlDataAdapter da=new SqlDataAdapter (cmd);
DataSet ds=new DataSet();
da.Fill (ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow gdata in GridView1 .Rows)
{
string email = gdata.Cells[3].Text.Trim();
MailMessage msg = new MailMessage();
msg.From = new MailAddress("your gmail id here");
msg.To.Add(email);
msg.Subject = TextBox1.Text;
msg.Body = TextBox2.Text;
msg.IsBodyHtml = true;
SmtpClient smt = new SmtpClient("smtp.gmail.com", 587);
smt.EnableSsl = true;
smt.Credentials = new System.Net.NetworkCredential("your gmail id here", "your gmail password");
smt.Send(msg);
Response.Write("message send");
}
}
}
Code Generate the following output
Comments
Post a Comment