C# 调用outlook 发送邮件
1.
這個(gè)是調(diào)用IE Mailto 來發(fā)送的,調(diào)用win API
首先要添加引用using System.Runtime.InteropServices;
??? class Mailto?????????????????????? //與我聯(lián)系打開郵箱的類
??? {
??????? [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)//在菜單的單擊事件中調(diào)用方法
????? {
????????? Mailto.ShellExecute(0, String.Empty, "mailto:vcool011@hotmail.com?subject=這是標(biāo)題哦&body=這是文本內(nèi)容啊!!!!!!!!! C:\\avatar.xml", String.Empty, String.Empty, 1);
????? }
?
2 調(diào)用 IE方法
?????????? System.Diagnostics.Process.Start("mailto:abc@sina.com");
或
?????????? System.Diagnostics.Process.Start("mailto:liuyi.aspnet@163.com?subject=這是標(biāo)題哦&body=這是文本內(nèi)容啊!!!!!!!!!");
?
前面二種都不能添加附件發(fā)送
下面是可以添加附件發(fā)送的
?
3
引用MSMAPI32.OCX 來實(shí)現(xiàn),可添加附件
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();
?
?
總結(jié)
以上是生活随笔為你收集整理的C# 调用outlook 发送邮件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux ELF 详解3 -- Sym
- 下一篇: draw.io