日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C# 调用outlook 发送邮件

發布時間:2023/12/16 C# 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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();

?

?

總結

以上是生活随笔為你收集整理的C# 调用outlook 发送邮件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。