VS.NET通过OUTLOOK发邮件

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

//通過outlook發郵件
        public static void SendMailWithOutlook(string toEmail, string bodyEmail,string subjectEmail)
        {
            try
            {
                Microsoft.Office.Interop.Outlook.Application olapp = new Microsoft.Office.Interop.Outlook.Application();
                MailItem eMail = (MailItem)olapp.CreateItem(OlItemType.olMailItem);
                eMail.Subject = subjectEmail;
                eMail.To = toEmail;
                eMail.Importance = OlImportance.olImportanceHigh;
                eMail.BodyFormat = OlBodyFormat.olFormatHTML;
                eMail.Body = bodyEmail;
                eMail.HTMLBody = bodyEmail;
                eMail.Importance = OlImportance.olImportanceLow;
                ((_MailItem)eMail).Send();
            }
            catch
            {
                MessageBox.Show("郵件未能成功能發送,可能是OUTLOOK故障,\r\n請與管理員聯繫!", "MES系統", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

你可能感兴趣的:(.net)