Send a single mail with multiple Ids using ASP.net with database

Posted by Mandlaa under ASP.NET on 5/15/2013 | Points: 10 | Views : 3582 | Status : [Member] | Replies : 12
I have on table like this


Emp:

Id Name Email
1 a a@gmail.com
1 b b@gmail.com

3 c c@gmail.com

I have a one login page I wat login based on id,That id is equal =Emp.id send Email that particular id's corresponding how many email address are that all emails send email at a time,
How can i do this please give me some code on this




Responses

Posted by: aswinialuri-19361 on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
hi,
try this code hope it will workout you
in an click event using you can enter the multiple ids in to address it will send at a time single msg to all emails
using system.net.mail;
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage("aswinialuri@gmail.com", txt1_to.Text);

msg.IsBodyHtml = true;
msg.Subject=txt_sub.Text.ToString();
msg.Body=txt_body.Text.ToString();
NetworkCredential nc = new NetworkCredential("aswinialuri@gmail.com", "@@@@@@@@@@@@");
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = nc;
smtp.Send(msg);
}
Mark As answer if it helps you
Thanks& Regards


Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks for replying, Not working,
This multiple email id's getting database based on condition,
Please give me bloatware code fully

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
what is your requirement, when user login with id you want to send mail to that particular user....is that so?

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
yes,
once see my above table

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
take your database table in dataset or datatable and search fieldfor its data like below
 public void remindermail()

{

SqlCommand cmd = new SqlCommand("select * from mytable");
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
if (dt.Rows[0]["id"].ToString() == "1")
{
/*string femail = dt.Rows[0]["email"].ToString();
string name = dt.Rows[0]["name"].ToString();*/

sendmail(dt.Rows[0]["email"].ToString(), dt.Rows[0]["name"].ToString());
}
else if (dt.Rows[0]["id"].ToString() == "3")
{
sendmail(dt.Rows[0]["email"].ToString(), dt.Rows[0]["name"].ToString());

}

}

}
public void sendmail(string email, string name)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("ankitsaxena22@rediffmail.com");
msg.To.Add(email);
msg.Subject = "appy budday";

msg.Body = myString.ToString();
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("", "");
smtp.EnableSsl = true;
smtp.Send(msg);

}


Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
Hi i am getting One mail only,
Suppose i have id's two same but email id's different,
I want send email all emails based on id,
please once see my code in attachment
 Download source file

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
so what is the primary key in your table how you will recognize each record

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
so what is the primary key in your table how you will recognize each record

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mandlaa on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
There is no primary key in this table,

For suppose
I writting this query =select email from send where id=1
It will display all emails



Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
atleast take one field as primary key or you can add one more field in that table by name secondaryemail
and then can change code according to this
if (dt.Rows.Count > 0)


{

if (dt.Rows[0]["id"].ToString() == "1")

{

string firstemail = dt.Rows[0]["Femail"].ToString();
string secondemail=dt.Rows[0]["Semail"].ToString();
string name = dt.Rows[0]["name"].ToString();*/

sendmail(firstemail , secondemail,name);

}

else if (dt.Rows[0]["id"].ToString() == "3")

{

sendmail(dt.Rows[0]["email"].ToString(), dt.Rows[0]["name"].ToString());



}



}
public void sendmail(string Femail,string Semail ,string name)

{

MailMessage msg = new MailMessage();

msg.From = new MailAddress("ankitsaxena22@rediffmail.com");

msg.To.Add(Femail);
msg.To.Add(Semail);

msg.Subject = "appy budday";



msg.Body = myString.ToString();

msg.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();

smtp.Host = "smtp.gmail.com";

smtp.Port = 587;

smtp.Credentials = new System.Net.NetworkCredential("", "");

smtp.EnableSsl = true;

smtp.Send(msg);



}


Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Annaharris on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Aswinialuri, the code that you have shared for sending single mail at multiple id's is not working.

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Annaharris,
it is worked for at a time you can send multiple emails like our gmail
i thought she asked like that
Thanks

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Mandlaa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response