2017-05-07 2 views
-2

Ich versuche, eine Nachricht mit datagridview Inhalt zu senden. Ich habe den folgenden Fehlerder Name htmlMessageBody existiert nicht im aktuellen Kontext

den Namen "htmlMessageBody" nicht

// Create a message with datagridview contents in its body and set up the recipients. 
System.Net.Mail.MailMessage myMessage = new System.Net.Mail.MailMessage(); 
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); 
//Try 
myMessage.From = new MailAddress("[email protected]"); 
//place here from address 
myMessage.To.Add("[email protected]"); 
//place here to address 
myMessage.CC.Add("[email protected]"); 
//place here copy address 
myMessage.BodyEncoding = Encoding.UTF8; 
myMessage.IsBodyHtml = true; 
//call method, creating HTML from datagridview 
myMessage.Body = htmlMessageBody(DataGridView1).ToString(); 
//place here your subject 
myMessage.Subject = "Subject"; 

//place here SMTP server 

SmtpServer.Port = 587; 
SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "xxxxx"); 
SmtpServer.EnableSsl = true; 
SmtpServer.Send(myMessage); 
MessageBox.Show("mail Send"); 
+3

Also, was macht Sie glauben, dass der Name htmlMessageBody *** *** im aktuellen Kontext existieren sollte? –

Antwort

1

Sie müssen in dem aktuellen Kontext existiert htmlMessageBody definieren:

private string htmlMessageBody(DataGridView dataGridView) 
{ 
    // Code goes here 
} 

Schauen Sie sich diese SO Fragen einige Beispielimplementierungen: one und two.

Verwandte Themen