⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapi.cs

📁 一个通用的数据库访问层
💻 CS
字号:
using System;
using System.Runtime.InteropServices;

namespace YariSoft.Utils
{

	public class Mapi
	{
		[StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
		private class MapiRecipDesc
		{ 
			public int		ulReserved			= 0;
			public int		ulRecipClass		= 1;      
			public string	lpszName			= ""; 
			public string	lpszAddress			= "";      
			public int		ulEIDSize			= 0; 
			public IntPtr	lpEntryID			= IntPtr.Zero;      
			
			public MapiRecipDesc()
			{
			}

			public MapiRecipDesc( string Address, int RecipClass ):this()
			{
				this.lpszAddress = Address;
				this.ulRecipClass = RecipClass;
			}
		} 

		[StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi )]
		private class MapiMessage 
		{ 
			public int		ulReserved			= 0;      
			public string	lpszSubject			= "";      
			public string	lpszNoteText		= "";      
			public string	lpszMessageType		= ""; 
			public string	lpszDateReceived	= ""; 
			public string	lpszConversationID	= "";      
			public int		flFlags				= 0;      
			public object	lpOriginator		= null;
			public int		nRecipCount			= 0;      
			public IntPtr	lpRecips			= IntPtr.Zero;      
			public int		nFileCount			= 0;      
			public object	lpFiles				= null;           
			
			public MapiMessage()
			{
			}

			public void Dispose()
			{
				this.DeleteMapiRecipDesc();
			}

			public MapiMessage( string Address, string Subject, string NoteText ):this()
			{
				this.lpszSubject	= Subject;
				this.lpszNoteText	= NoteText;
				this.nRecipCount	= 1;	

				this.AllocateMapiRecipDesc ( Address, ref this.lpRecips, 1 );
			}

			private void AllocateMapiRecipDesc( string Address, ref IntPtr Pointer, int RecipClass )
			{
				MapiRecipDesc recip = new MapiRecipDesc ( Address, RecipClass );
				IntPtr ptr			= Marshal.AllocHGlobal( Marshal.SizeOf( typeof( MapiRecipDesc )));
				Marshal.StructureToPtr( recip, ptr, false );
				Pointer				= ptr;
				return;
			}


			private void DeleteMapiRecipDesc()
			{
				if( this.lpRecips != IntPtr.Zero ){
					Marshal.DestroyStructure( this.lpRecips, typeof(MapiRecipDesc) );
					Marshal.FreeHGlobal( this.lpRecips );
				}	
			}
		} 

		[System.Runtime.InteropServices.DllImport( "MAPI32.DLL")]
		private static extern int MAPISendMail(	int			lhSession, 
												int			ulUIParam,
												MapiMessage lpMessage,
												int			flFlags, 
												int			ulReserved );

		public static int Send( string Address, string Subject, string Text, bool Anonymous )
		{
			int result = 0;
			MapiMessage lpMessage = new MapiMessage ( Address, Subject, Text );
			try{
				result = MAPISendMail( 0, 0, lpMessage, 0, 0 );	
			} finally{
				lpMessage.Dispose();
			}
			return result;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -