码迷,mamicode.com
首页 > Windows程序 > 详细

C#调用outlook发送邮件

时间:2020-02-18 10:03:06      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:class   create   邮件   ===   rop   help   microsoft   office   chm   

using System;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace ConsoleApp5
{
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 <4; 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 = "各收件人,<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;
    }
}

}

C#调用outlook发送邮件

标签:class   create   邮件   ===   rop   help   microsoft   office   chm   

原文地址:https://www.cnblogs.com/zhujie-com/p/12324511.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!