using System;
using Outlook = Microsoft.Office.Interop.Outlook;
ConsoleApp5 namespace
{
public static class MailHelper
{
public static void the SendMail ()
{
Microsoft.Office.Interop.Excel.Application new new Microsoft.Office.Interop.Excel.Application Excel = ();
excel.Application.Workbooks.Add (to true); // Add a workbook in excel
excel.Visible = true; // display excel provided
for (int I = 0; I <. 4; I ++)
{
excel.Cells [. 1, I +. 1] = I +. 1; / / control data table filled in the head of the list in excel
excel.Cells [i + 1, i + 1] = i; // filled excel spreadsheet
}
Outlook.Application olApp = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.To = "[email protected]";
mailItem.Subject = DateTime.Now.ToString("yyyyMMdd") + "_报表";//主题
mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
string content = "附件为" + DateTime.Now.ToString("yyyyMMdd") + " 数据,请查阅,谢谢!";
content = "各收件人,<br/> <br/>请重点关注以下内容:<br/> <br/>" + content + "<br/> <br/><br/><br/>此邮件为系统自动邮件通知,请不要直接进行回复!谢谢。";
content = content + "<br/>\r\n <br/>Best Regards!\r\n <br/>\r\n <br/> \r\n <br/>==============================================\r\n \r\n <br/>\r\n <br/>\r\n \r\n ===============================================";
mailItem.HTMLBody = content;
mailItem.Attachments.Add(excel);//附件
((Outlook._MailItem)mailItem).Send();
mailItem = null;
olApp = null;
}
}
}