网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > C# > 正文
C#中使用MAPI发送E-Mail
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/14
下载{$ArticleTitle}原创论文样式

以下是从DevExpress代码中摘出来的,修改前先贴出来共享一下,有更好的建议请留言
直接构造该类,会把传入参数作为默认值来调用Outlook的发送窗体,对于要求直接发送的,此类不适用

注意:构造时,传入的Handle应为Application.Run(form)或form.ShowDialog()中form的指针,或使用form.BeginInvoke()调用到窗体,否则将无法显示窗体和发送

using System;
using System.IO;
using System.Runtime.InteropServices;

namespace HKH.Common
{

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class MapiMessage
{
public int reserved;
public string subject;
public string noteText;
public string messageType;
public string dateReceived;
public string conversationID;
public int flags;
public IntPtr originator;
public int recipCount;
public IntPtr recips;
public int fileCount;
public IntPtr files;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class MapiRecipDesc
{
public int reserved;
public int recipClass;
public string name;
public string address;
public int eIDSize;
public IntPtr entryID;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class MapiFileDesc
{
public int reserved;
public int flags;
public int position;
public string pathName;
public string fileName;
public IntPtr fileType;
}
public class MAPI
{
static#region static
private const int MapiLogonUI = 0x00000001;
private const int MAPI_DIALOG = 0x8;

[DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)]
private static extern int MAPISendMail(IntPtr session, IntPtr uiParam,
MapiMessage message, int flags, int reserved);
[DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)]
private static extern int MAPILogon(IntPtr hwnd, string profileName, string password,
int flags, int reserved, ref IntPtr session);
[DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)]
private static extern int MAPILogoff(IntPtr session, IntPtr hwnd,
int flags, int reserved);

static IntPtr OffsetPtr(IntPtr ptr, Type structureType, int offset)
{
return (IntPtr)((long)ptr + offset * Marshal.SizeOf(structureType));
}
#endregion

private string files;
private string subject = String.Empty;
private string body = String.Empty;
private string recipentName = String.Empty;
private string recipientAddress = String.Empty;
private IntPtr handle = IntPtr.Zero;
private IntPtr session = IntPtr.Zero;
private int error = 0;

/**//// <summary>
/// Create and Send a Mail
/// </summary>
/// <param name="handle">Application.Run(form) OR form.ShowDialog() form.Handle</param>
/// <param name="files"></param>
/// <param name="mailSubject"></param>
/// <param name="mailBody"></param>
/// <param name="recipentName"></param>
/// <param name="recipientAddress"></param>
public MAPI(IntPtr handle, string files, string mailSubject, string mailBody, string recipentName, string recipientAddress)
{
this.files = files;
this.subject = mailSubject;
this.body = mailBody;
this.recipentName = recipentName;
this.recipientAddress = recipientAddress;
if (Logon(handle))

  • 上一篇资讯: c#更换皮肤代码
  • 下一篇资讯: 用c#监控网络流量
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号