I have a datagrid view with three columns and one button column. My aim is that I want to send an automatic email to the specified mail id when I click on the button in button column of the datagrid view.
Is it possible to do so that if I click on the button column, a mail will be sent to this mail id: abc@shx.com?
The corresponding row values will be attached to body of the mail. Is it possible to do these three steps:
- Handling the click event (button column click event)..
- Finding the corresponding row values and attached to mail body
- Sending the email to given mail id (if I click on the button column (only on the button))
Would anyone suggest me any ideas for doing these all? I am doing WinForms application using C#.
EDIT :
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex != 3)
return;
object col1 = dataGridView1.Rows[e.RowIndex].Cells[0].Value;
object col2 = dataGridView1.Rows[e.RowIndex].Cells[1].Value;
object col3 = dataGridView1.Rows[e.RowIndex].Cells[2].Value;
}
But I don’t know how to get the row values and send an email.
In your example you already got the row values corresponding to the row being clicked:
as far as sending an email in .NET is concerned, you could use the SmtpClient class. Here’s an example with Gmail:
Of course you should adapt your Smtp server configuration to match your settings.