📄 testnetmapi.cs
字号:
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// File: TestNetMAPI.cs
// Description: Test program for .NET Extended MAPI wrapper
// Works in Windows CE and Windows XP with Outlook 2000 and 2003, maybe others but untested
//
// Copyright (C) 2006, Noel Dillabough
//
// This source code is free to use and modify provided this notice remains intact and that any enhancements
// or bug fixes are posted to the CodeProject page hosting this class for all to benefit.
//
// Usage: see the Codeproject article at http://www.codeproject.com
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using MAPIEx;
namespace TestNetMAPI
{
/// <summary>
/// Test program for NetMAPI Wrapper
/// </summary>
class TestNetMAPI
{
/// <summary>
/// TestMAPI Main
/// </summary>
[STAThread]
static void Main(string[] args)
{
if(NetMAPI.Init()) {
SendTest();
ReceiveTest();
NetMAPI.Term();
}
}
/// <summary>
/// To send a message: (assumes NetMAPI Init was successfully called)
/// -create a new message, set its priority if you like
/// -set its recipients (TO, CC, BCC etc)
/// -call send
/// </summary>
static void SendTest()
{
string strEmail="noel@nospam.ca";
string strSubject="Subject";
string strBody="Body";
// simplified method to send a message for quick and dirty usage (last argument is attachment, empty means none)
NetMAPI.SendEmail(strEmail,strSubject,strBody,"");
// more control method to send to multiple recipients, piorities, CC, BCC, etc
if(NetMAPI.CreateMessage(strSubject,strBody,Priority.IMPORTANCE_LOW)) {
NetMAPI.AddRecipient(strEmail,RecipientType.MAPI_TO);
NetMAPI.AddRecipient(strEmail,RecipientType.MAPI_CC);
NetMAPI.Send();
}
}
/// <summary>
/// To receive a message: (assumes NetMAPI Init was successfully called)
/// -get the contents table
/// -iterate through the messages using GetNextMessage() (sample below gets only unread messages)
/// -get message parameters from Message
/// </summary>
static void ReceiveTest()
{
if(NetMAPI.GetContents()) {
Message m=new Message();
while(NetMAPI.GetNextMessage(ref m,true)) {
Console.WriteLine("Mail from: {0} Subject: {1}",m.SenderName,m.Subject);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -