C#调用outlook发送邮件
2021-03-19 17:26
标签:class create 邮件 === rop help microsoft office chm using System; namespace ConsoleApp5 } C#调用outlook发送邮件 标签:class create 邮件 === rop help microsoft office chm 原文地址:https://www.cnblogs.com/zhujie-com/p/12324511.html
using Outlook = Microsoft.Office.Interop.Outlook;
{
public static class MailHelper
{
public static void SendMail()
{
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Application.Workbooks.Add(true);//在excel中添加一个工作薄
excel.Visible = true;//设置excel显示
for (int i = 0; i
{
excel.Cells[1, i + 1] = i+1;//将数据表格控件中的列表头填充到excel中
excel.Cells[i + 1, i + 1] = i;//填充到excel表格
} Outlook.Application olApp = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.To = "563524869@qq.com";
mailItem.Subject = DateTime.Now.ToString("yyyyMMdd") + "_报表";//主题
mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
string content = "附件为" + DateTime.Now.ToString("yyyyMMdd") + " 数据,请查阅,谢谢!";
content = "各收件人,
请重点关注以下内容:
" + content + "
此邮件为系统自动邮件通知,请不要直接进行回复!谢谢。";
content = content + "
\r\n
Best Regards!\r\n
\r\n
\r\n
==============================================\r\n \r\n
\r\n
\r\n \r\n ===============================================";
mailItem.HTMLBody = content;
mailItem.Attachments.Add(excel);//附件
((Outlook._MailItem)mailItem).Send();
mailItem = null;
olApp = null;
}
}