유틸리티 기능
이 문서는 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은 새 메시지를 작성할 때 Yes, No, Maybe와 같은 투표 버튼을 추가하여 설문조사를 만들 수 있게 합니다. 이 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(Reply/Reply All) 및 FW(Forward) 메시지를 만들 수 있게 합니다. 원본 메시지는 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 이상은 음성 메일과 이메일을 하나의 메일함에 결합한 통합 메일링을 제공합니다. 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 이상에서는 메시지를 작성 중에 메일 팁을 제공할 수 있습니다 - 메시지 전송 전에 수신자에 대한 정보가 제공됩니다. 예를 들어 수신자 주소가 유효하지 않거나 자동 부재 중 회신이 설정된 경우를 알려줍니다. Exchange Server 2010 Service Pack 1 이상이 필요합니다.
GetMailTipsOptions 보낸 사람, 받는 사람 및 요청할 팁 종류를 지정합니다 (MailTipsType); GetMailTips 하나를 반환합니다 MailTips 받는 사람당 객체. 두 번째 인수는 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();