Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hello,,,
My Question is How to send gmail to multiple person in asp.net.I have send email one to one person through asp.net code.But now i want to send email one to many person.
Like...

from=me@gmail.com
to=you1@gmail.com,you2@gmail.com


Code of send email one to one person


using System.Net.Mail;

protected void btnSend_Click(object sender, EventArgs e)
{

string from = "megmail@gmail.com";
string to = "you@gmail.com";

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new MailAddress(from, "One Ghost", System.Text.Encoding.UTF8);
mail.Subject = txtsubject.Text;
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = txtMsg.Text;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;

SmtpClient client = new SmtpClient();

client.Credentials = new System.Net.NetworkCredential(from, Password);

client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
try
{

client.Send(mail);
}
catch (Exception ex)
{
Exception ex2 = ex;
string errorMessage = string.Empty;
while (ex2 != null)
{
errorMessage += ex2.ToString();
ex2 = ex2.InnerException;
}
HttpContext.Current.Response.Write(errorMessage);
//txtMsg.Text = ex.Message;
//mail.Subject = ex.Message;
//mail.Body = txtMsg.Text;
}
}
Posted
Comments
joshrduncan2012 3-Apr-13 9:37am    
string to = "you@gmail.com";

Just add to this for all addresses you want to send to.

Just call
C#
mail.To.Add(to);
for each email address you need.
 
Share this answer
 
Just use the below code

string ToMail="you1@gmail.com,you2@gmail.com,you3@gmail.com";

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(ToMail);

The e-mail addresses to add to the System.Net.Mail.MailAddressCollection.
Multiple e-mail addresses must be separated with a comma character (",").

Regards,
Manoj
 
Share this answer
 
To specify multiple addresses you need to use the To property which is a MailAddressCollection
C#
message.To.Add("You1@test.com, You2@test.com"));
 
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