• .NET使用本地outlook客户端发送邮件


    1、添加Microsoft.Office.Interop.Outlook引用

    2、封装发送邮件方法

    using System;
    using System.Configuration;
    using System.Net.Mail;
    
    
    namespace ServiceMe.Apps.Business.Common.Unity
    {
        /// <summary>
        /// 发送邮件帮助类
        /// </summary>
        public class MailHelper
        {    

         #region 发送邮件 /// <summary> /// 发送邮件 /// </summary> /// <param name="sendusermail"></param> /// <param name="mailtitle"></param> /// <param name="mailcontent"></param> /// <returns></returns> public static bool Send(string sendusermail, string mailtitle, string mailcontent) { try { Microsoft.Office.Interop.Outlook.Application olApp = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.MailItem mailItem = (Microsoft.Office.Interop.Outlook.MailItem)olApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); mailItem.To = sendusermail; mailItem.Subject = mailtitle; mailItem.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML; mailItem.HTMLBody = mailcontent; ((Microsoft.Office.Interop.Outlook._MailItem)mailItem).Send(); mailItem = null; olApp = null; } catch (Exception e) { Console.WriteLine(e); return false; } return true; } #endregion } }

    3、调用示例

    MailHelper.Send("xxxx@163.com", "测试邮件", "请注意,这是一封测试邮件!");

    4、示例结果

  • 相关阅读:
    C#-获取磁盘,cpu,内存信息
    C#-WiFi共享
    C#-WiFi共享
    C#-DES加解密
    C#-DES加解密
    C#-播放器相关
    C#-播放器相关
    Windowsw核心编程 第13章 Windows内存结构
    Windowsw核心编程 第13章 Windows内存结构
    C#-CHTTPDownload
  • 原文地址:https://www.cnblogs.com/vuenote/p/11177152.html
Copyright © 2020-2023  润新知