ユーティリティ機能
この記事では、EWSクライアントのいくつかの小さな機能をまとめています:投票の送信、検証に失敗したサーバー証明書の受け入れ、メッセージへのサーバー上での返信と転送、EWSリクエストへのヘッダー追加、統合メッセージング、およびメールヒント。
本記事のサンプルは以下のヘッダーと名前空間を使用しています:
#include <MailMessage.h>
#include <MailAddress.h>
#include <MailAddressCollection.h>
#include <Attachment.h>
#include <AttachmentCollection.h>
#include <Mapi/FollowUpOptions.h>
#include <Clients/Exchange/WebService/EWSClient/EWSClient.h>
#include <Clients/Exchange/WebService/EWSClient/IEWSClient.h>
#include <Clients/Exchange/WebService/UnifiedMessaging/UnifiedMessagingConfiguration.h>
#include <Clients/Exchange/WebService/MailTips/GetMailTipsOptions.h>
#include <Clients/Exchange/WebService/MailTips/MailTips.h>
#include <Clients/Exchange/WebService/MailTips/MailTipsType.h>
#include <Clients/Exchange/WebService/MailTips/OutOfOfficeMailTip.h>
#include <Clients/Exchange/WebService/MailTips/ReplyBody.h>
#include <Clients/Exchange/ExchangeMailboxInfo.h>
#include <Clients/Exchange/ExchangeMessageInfo.h>
#include <Clients/Exchange/ExchangeMessageInfoCollection.h>
#include <net/service_point_manager.h>
#include <net/secure_protocols/ssl_stream.h>
#include <system/array.h>
#include <system/convert.h>
using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Mapi;
using namespace Aspose::Email::Clients::Exchange;
using namespace Aspose::Email::Clients::Exchange::WebService;
投票オプション付きメッセージの送信
Microsoft Outlook は新規メッセージ作成時に「はい」「いいえ」「未定」などの投票ボタンを追加して投票を作成できます。その FollowUpOptions クラスはこれらのボタンをその中に保持します VotingButtons プロパティは、セミコロン区切りのリストとして指定します。
投票オプション付きメッセージの作成と送信
のオーバーロード 送信 それは FollowUpOptions オブジェクトは投票ボタンを添付した状態でExchangeを介してメッセージを送信するので、受信者はOutlookでそれらを見ることができます。
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
String address = u"firstname.lastname@example.com";
SharedPtr<MailMessage> message = MakeObject<MailMessage>(address, address, u"Flagged message",
u"Make it nice and short, but descriptive.");
SharedPtr<FollowUpOptions> options = MakeObject<FollowUpOptions>();
options->set_VotingButtons(u"Yes;No;Maybe;Exactly!");
try
{
client->Send(message, options);
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();
無効または期限切れの SSL 証明書を無視またはバイパスする
Exchangeサーバーの証明書が期限切れまたは検証できない場合 - 自己署名証明書を使用したテストサーバーで典型的です - 接続は例外で失敗します。検証コールバックは次のように登録されます System::Net::ServicePointManager そのような証明書について決定します。常に戻り値を返すコールバック true が受け入れます。最初のリクエストの前に一度登録し、信頼できる環境でのみ使用してください:インポスター サーバーへの保護をオフにします。
// Accepts every server certificate, whatever the validation result
static bool AcceptAllCertificates(SharedPtr<Object> sender,
SharedPtr<Security::Cryptography::X509Certificates::X509Certificate> certificate,
SharedPtr<Security::Cryptography::X509Certificates::X509Chain> chain,
Net::Security::SslPolicyErrors sslPolicyErrors)
{
return true;
}
Net::ServicePointManager::set_ServerCertificateValidationCallback(
Net::Security::RemoteCertificateValidationCallback(AcceptAllCertificates));
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://exchange.test.local/ews/exchange.asmx", u"username", u"password");
client->Dispose();
MSGファイルからREおよびFWメッセージを作成
IEWSClient 開発者がサーバー上のメッセージから RE(返信/全員返信)と FW(転送)メッセージを作成できるようにします。元メッセージは ExchangeMessageInfo から参照してください ExchangeMessageInfoCollection が返す ListMessages()。もう一つの引数は MailMessage テキストと添付ファイルを含めて返信します。この作業を行う手順:
- 初期化します。 IEWSClient 有効な資格情報を提供することでオブジェクトが取得できます。
- 返信するメッセージを探します。
- 呼び出す Reply(), ReplyAll() および Forward() レスポンスを送信するメソッド。
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://exchange.domain.com/ews/Exchange.asmx", u"username", u"password");
try
{
// a message to respond to
client->Send(MakeObject<MailMessage>(u"user@domain.com", u"user@domain.com", u"TestMailRefw", u"The original message"));
SharedPtr<ExchangeMessageInfoCollection> messages = client->ListMessages(client->get_MailboxInfo()->get_InboxUri());
// the text and the attachments of the response
SharedPtr<MailMessage> response = MakeObject<MailMessage>(u"user@domain.com", u"user@domain.com", u"TestMailRefw", u"The response");
response->get_Attachments()->Add(Attachment::CreateAttachmentFromString(u"Test attachment 1", u"Attachment Name 1"));
response->get_Attachments()->Add(Attachment::CreateAttachmentFromString(u"Test attachment 2", u"Attachment Name 2"));
client->Reply(response, messages->idx_get(0));
client->ReplyAll(response, messages->idx_get(0));
client->Forward(response, messages->idx_get(0));
}
catch (System::Exception& ex)
{
Console::WriteLine(u"Error in program: " + ex->get_Message());
}
client->Dispose();
EWSリクエストへのヘッダー追加
カスタム HTTP ヘッダーはクライアントが送信するすべての EWS リクエストに追加できます。一般的なケースは X-AnchorMailbox、アプリケーションのリクエストをメールボックスを保持するサーバーへルーティングし、Exchange Online のスロットリング対策に役立ちます。次は AddHeader メソッド IEWSClient そのようなヘッダーを追加します。
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
client->AddHeader(u"X-AnchorMailbox", u"username@domain.com");
SharedPtr<ExchangeMessageInfoCollection> messages = client->ListMessages(client->get_MailboxInfo()->get_InboxUri());
Console::WriteLine(u"Messages: " + Convert::ToString(messages->get_Count()));
client->Dispose();
統合メッセージングの操作
Exchange Server 2010 以降は音声メールとメールを 1 つのメールボックスに統合します――統合メッセージングです。 GetUMConfiguration は UnifiedMessagingConfiguration メールボックスの設定:統合メッセージングが有効か、電話でメッセージ再生に使用する番号など。クライアントは発信呼び出しの開始、ID で通話情報の取得、切断も行えます。
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://exchange.domain.com/ews/Exchange.asmx", u"username", u"password");
SharedPtr<UnifiedMessagingConfiguration> configuration = client->GetUMConfiguration();
Console::WriteLine(u"Unified messaging enabled: " + Convert::ToString(configuration->get_UMEnabled()));
Console::WriteLine(u"Play on phone: " + Convert::ToString(configuration->get_PlayOnPhoneEnabled()) +
u", dial string: " + configuration->get_PlayOnPhoneDialString());
client->Dispose();
メールチップの取得
Exchange Server 2010 以降はメッセージ作成中に mail tips を提供できます——送信前に受信者情報を知らせます。ヒントはたとえば受信者アドレスが無効、受信者が外出中返信を設定していることなどを報告します。Exchange Server 2010 Service Pack 1 以降が必要です。
GetMailTipsOptions 送信者、受信者、要求するヒントの種類を指定します (MailTipsType); GetMailTips 1 件返します MailTips 受信者ごとのオブジェクト。次の第2引数は MailAddress 以下のコンストラクタ、 trueとして表し、アドレスの構文チェックをスキップします。
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://exchange.domain.com/ews/Exchange.asmx", u"username", u"password");
SharedPtr<MailAddressCollection> recipients = MakeObject<MailAddressCollection>();
recipients->Add(MakeObject<MailAddress>(u"test.exchange@ex2010.local", true));
recipients->Add(MakeObject<MailAddress>(u"invalid.recipient@ex2010.local", true));
SharedPtr<GetMailTipsOptions> options = MakeObject<GetMailTipsOptions>(
MakeObject<MailAddress>(u"administrator@ex2010.local", true), recipients, MailTipsType::All);
try
{
for (SharedPtr<MailTips> tip : client->GetMailTips(options))
{
if (tip->get_OutOfOffice() != nullptr)
{
Console::WriteLine(u"Out of office: " + tip->get_OutOfOffice()->get_ReplyBody()->get_Message());
}
if (tip->get_InvalidRecipient())
{
Console::WriteLine(u"The recipient address is invalid: " + tip->get_RecipientAddress()->get_Address());
}
}
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();