我编写了一个代码,我可以使用 c# 向 gmail.com 发送电子邮件,并且运行良好。现在我想将我的 datagridview1 放在电子邮件正文中并发送。有人可以告诉我我该怎么做吗?我搜索了很多,但我只找到了无用的信息和 asp.net 代码。
这是我发送电子邮件的实际代码。我的 datagridview 名称是:datagridview1
private void btnSend_Click_1(object sender, EventArgs e)
{
// Create a message with datagridview contents in its body and set up the recipients.
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("youraccount@yahoo.com");
mail.To.Add("jpbritopoker@gmail.com");
mail.Subject = "This is the subject of the mail";
mail.Body = "Here i want my datagridview1";
client.Send(mail);
}