उपयोगिता सुविधाएँ
यह लेख 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 ऑब्जेक्ट संदेश को एक्सचेंज के माध्यम से मतदान बटन के साथ भेजता है, ताकि प्राप्तकर्ता उन्हें आउटलुक में देख सकें।
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 प्रमाणपत्र को अनदेखा या बायपास करें
जब एक्सचेंज सर्वर का प्रमाणपत्र समाप्त हो गया हो या सत्यापित नहीं किया जा सके - यह आमतौर पर परीक्षण सर्वरों में स्व-हस्ताक्षरित प्रमाणपत्रों के साथ होता है - कनेक्शन एक अपवाद के साथ विफल हो जाता है। एक वैधता कॉलबैक जो पंजीकृत किया गया है 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 और बाद के संस्करण mail tips प्रदान कर सकते हैं जब संदेश लिखा जा रहा हो - प्राप्तकर्ताओं के बारे में जानकारी भेजे जाने से पहले। एक टिप उदाहरण के लिए बताता है कि प्राप्तकर्ता का पता अमान्य है या प्राप्तकर्ता ने Out of Office उत्तर सेट किया है। 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();