C# 调用outlook 发送邮件

1.

这个是调用IE Mailto 来发送的,调用win API
首先要添加引用using System.Runtime.InteropServices;

    class Mailto                       //与我联系打开邮箱的类
    {
        [DllImport("shell32.dll", EntryPoint = "ShellExecuteA")]
        public static extern int ShellExecute(
         int hwnd,
         String lpOperation,
         String lpFile,
         String lpParameters,
         String lpDirectory,
         int nShowCmd
         );

    }

   private void call_me_Click(object sender, EventArgs e)//在菜单的单击事件中调用方法
      {
          Mailto.ShellExecute(0, String.Empty, "mailto:vcool011@hotmail.com?subject=这是标题哦&body=这是文本内容啊!!!!!!!!! C:\\avatar.xml", String.Empty, String.Empty, 1);
      }

 

2 调用 IE方法
           System.Diagnostics.Process.Start("mailto:abc@sina.com");

           System.Diagnostics.Process.Start("mailto:liuyi.aspnet@163.com?subject=这是标题哦&body=这是文本内容啊!!!!!!!!!");

 

前面二种都不能添加附件发送

下面是可以添加附件发送的

 

3

引用MSMAPI32.OCX 来实现,可添加附件

      MAPISession MAPIS1 = new MAPISession();
                MAPIMessagesClass MAPIM1 = new MAPIMessagesClass();
                MAPIS1.NewSession = true;
                MAPIS1.LogonUI = false;
                MAPIS1.DownLoadMail = false;

                string m_path;
                string m_file_name;
                string m_file;

                m_path = "c:\\";

                m_file_name = "Log.txt";
                m_file = m_path + m_file_name;

                MAPIS1.SignOn();

                MAPIM1.SessionID = MAPIS1.SessionID;
                MAPIM1.Compose();

                MAPIM1.AddressResolveUI = true;
                MAPIM1.AttachmentIndex = 0;

                MAPIM1.AttachmentPathName = m_file;
                MAPIM1.AttachmentName = m_file_name;

                MAPIM1.MsgSubject = "The Title ";
                MAPIM1.MsgNoteText = "The Body ";

                MAPIM1.Send(true);

                MAPIS1.SignOff();

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值