0

Hello i have my code to send datagridview to email and it is running very well. The problem is that it is just sending to my email, and not to other people email , my email is the Network Credential . How can i send it to other people?

Pesquisar_Items pesquisar = new Pesquisar_Items();

var client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Credentials = new NetworkCredential("jpbritopoker@gmail.com", "***");

var mail = new MailMessage();
mail.From = new MailAddress("nervir@epnervir.com");
mail.To.Add(textBox1.Text);
mail.IsBodyHtml = true;
mail.Subject = textBox2.Text;

string mailBody = "<table width='100%' style='border:Solid 1px Black;'>"; ;

foreach (DataGridViewRow row in itemDataGridView.Rows)
{
    mailBody += "<tr>";
    foreach (DataGridViewCell cell in row.Cells)
    {
        mailBody += "<td>" + cell.Value + "</td>";
    }
    mailBody += "</tr>";
}
mailBody += "</table>";

//your rest of the original code
mail.Body = mailBody;
client.Send(mail);
MessageBox.Show("O email foi enviado com sucesso");
this.Close();
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
  • http://stackoverflow.com/questions/3209129/unable-to-send-an-email-to-multiple-addresses-recipients-using-c-sharp – michele May 15 '13 at 15:29

2 Answers2

1

I don't think Google's smtp server will allow you to change the sender's email address as you are doing. It would be something typical of someone trying to use their server to send spam. If you change your code to appear as if the email is coming from jpbritopoker@gmail.com it may work. Something like this:

mail.From = new MailAddress("jpbritopoker@gmail.com");

You were doing:

mail.From = new MailAddress("nervir@epnervir.com");
Icarus
  • 63,293
  • 14
  • 100
  • 115
1

did you try something like this

mail.To.Add("foo1@dn.com")
mail.To.Add("foo2@dn.com")
mail.To.Add("foo3@dn.com")

or

mail.CC.Add("foo3@dn.com")
Vikramsinh Shinde
  • 2,742
  • 2
  • 23
  • 29