What I want is to be able to send an email with data that is digitized from my Windows CE project, the problem is that I create the website and put my two codes both the email and export data to excel but then two problems arise.
With the subject of excel, how do I tell my program to choose the 14 Labels and the 7 TextBox that are found in my Windows CE project ?, Because if I make the call it tells me that there are no such Labels and TextBoxes.
How can the mail code which is also in the web service send me the information of that Excel since it sends me the file but sends it to me with some words that I gave as an example? , if I call the method which contains the excel export within that I get an error.
How do I call that service from my Windows CE project?
I enclose the codes I am handling
EXCEL CODE
public void exporta_a_excel()
{
Microsoft.Office.Interop.Excel.ApplicationClass excel = new ApplicationClass();
excel.Application.Workbooks.Add(true);
int ColumnIndex = 0;
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
ColumnIndex++;
excel.Cells[1, ColumnIndex] = col.Name;
}
int rowIndex = 0;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
rowIndex++;
ColumnIndex = 0;
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
ColumnIndex++;
excel.Cells[rowIndex + 1, ColumnIndex] = row.Cells[col.Name].Value;
}
}
excel.Visible = true;
Worksheet worksheet = (Worksheet)excel.ActiveSheet;
worksheet.Activate();
}
MAIL CODE
public void Correo()
{
MailMessage objeto_mail = new MailMessage();
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp-mail.outlook.com";
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "xxxx");
objeto_mail.From = new MailAddress("[email protected]");
objeto_mail.To.Add(new MailAddress("[email protected]"));
objeto_mail.To.Add(new MailAddress("[email protected]"));
objeto_mail.To.Add(new MailAddress("[email protected]"));
objeto_mail.Subject = "Pedidos";
//List<string> Archivo = new List<string>();
//Archivo.Add("");
//Archivo.Add("");
objeto_mail.IsBodyHtml = false;
objeto_mail.Body = "se hizo el pedido y la orden esta adjuntada en el correo con un excell";
client.EnableSsl = true;
//client.Send(objeto_mail);
using (var stream = new MemoryStream())
using (var writer = new StreamWriter(stream)) // using UTF-8 encoding by default
// using (var mailClient = new SmtpClient("localhost", 25))
// using (var message = new MailMessage("[email protected]", "[email protected]", "Just testing", "See attachment..."))
{
writer.WriteLine("Comma,Seperated,Values,..."); //ESTO ME SALED EN EL ARCHIVO EXCEL
writer.Flush();
stream.Position = 0; // read from the start of what was written
objeto_mail.Attachments.Add(new Attachment(stream, "Pedido.csv", "text/csv"));
client.Send(objeto_mail);
}
}
All this is in a web service, and make the call from the form of Windows CE in which is the database, the Labels and the TextBox and which until now makes the operation to update the data, the which must be inserted in the Excel which is sent by email.
The liberias that I am using for the mail are:
using OpenNETCF.Net.Mail;
using OpenNETCF.Net;
And the data that should go in the Excel are these: