Yardımcı Özellikler
Oy Seçeneği ile Mesaj Gönderme
Microsoft Outlook, yeni bir mesaj oluştururken kullanıcıların bir anket oluşturmasına izin verir. Bu, Evet, Hayır, Belki vb. gibi oy seçeneklerinin eklenmesiyle yapılır. Aspose.Email’in sunduğu FollowUpOptions sınıfı, oy seçeneklerinin değerini ayarlamak veya almak için kullanılabilecek VotingButtons özelliğini sağlar. Bu makale, bir anket oluşturmak için oy seçenekleriyle bir MapiMessage oluşturma ve ardından mesajı Exchange Web Service (EWS) istemcisiyle gönderme konusunda ayrıntılı bir örnek sunar.
Oy Seçenekleri ile Mesaj Oluşturma ve Gönderme
Aşağıdaki kod bölümü, yeni bir mesaj oluşturup ardından oy seçenekleriyle nasıl gönderileceğini gösterir.
String address = "firstname.lastname@aspose.com";
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
MailMessage message = createTestMessage(address);
// Set FollowUpOptions Buttons
FollowUpOptions options = new FollowUpOptions();
options.setVotingButtons("Yes;No;Maybe;Exactly!");
client.send(message, options);
Örneklerde Kullanılan Metodlar
Aşağıdaki kod bölümü, yukarıdaki örnekte kullanılan yöntemlerin nasıl kullanılacağını gösterir.
private static MailMessage createTestMessage(String address) {
MailMessage eml = new MailMessage(address, address, "Flagged message",
"Make it nice and short, but descriptive. The description may appear in search engines' search results pages...");
return eml;
}
MSG dosyalarından RE ve FW mesajları oluşturma
IEWSClient geliştiricilerin bir kaynak mesajdan RE (Reply/Reply All) ve FW (Forward) mesajları oluşturmasını sağlar. Kaynak mesaj, belirli bir ExchangeMessageInfo den ExchangeMessageInfoCollection IEWSClient.listMessages() ile elde edilen. Diğer argüman ise gerçek MailMessage RE veya FW mesajı olarak gönderilecek. Aşağıdaki kod bölümü, bir örnek hesabın nasıl oluşturulup mesaj gönderildiğini ve ardından bu örnek mesaj üzerinde Yanıt ve İleri Yönlendirme özelliklerinin nasıl gösterileceğini gösterir. Bu görevi gerçekleştirmek için:
- Geçerli kimlik bilgileri sağlayarak IEWSClient nesnesini başlatın.
- Birkaç örnek mesaj gönder.
- Mesaj göndermek için IEWSClient.reply(), IEWSClient.replyAll() ve IEWSClient.forward() fonksiyonlarını çağırın.
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credential);
try {
MailMessage message = new MailMessage("user@domain.com", "user@domain.com", "TestMailRefw - " + UUID.randomUUID().toString(),
"TestMailRefw Implement ability to create RE and FW messages from source MSG file");
client.send(message);
ExchangeMessageInfoCollection messageInfoCol = client.listMessages(client.getMailboxInfo().getInboxUri());
if (messageInfoCol.size() == 1)
System.out.println("1 message in Inbox");
else
System.out.println("Error! No message in Inbox");
MailMessage message1 = new MailMessage("user@domain.com", "user@domain.com", "TestMailRefw - " + UUID.randomUUID().toString(),
"TestMailRefw Implement ability to create RE and FW messages from source MSG file");
client.send(message1);
messageInfoCol = client.listMessages(client.getMailboxInfo().getInboxUri());
if (messageInfoCol.size() == 2)
System.out.println("2 messages in Inbox");
else
System.out.println("Error! No new message in Inbox");
MailMessage message2 = new MailMessage("user@domain.com", "user@domain.com", "TestMailRefw - " + UUID.randomUUID().toString(),
"TestMailRefw Implement ability to create RE and FW messages from source MSG file");
message2.getAttachments().addItem(Attachment.createAttachmentFromString("Test attachment 1", "Attachment Name 1"));
message2.getAttachments().addItem(Attachment.createAttachmentFromString("Test attachment 2", "Attachment Name 2"));
// Reply, Replay All and forward Message
client.reply(message2, messageInfoCol.get_Item(0));
client.replyAll(message2, messageInfoCol.get_Item(0));
client.forward(message2, messageInfoCol.get_Item(0));
} catch (java.lang.RuntimeException ex) {
System.out.println("Error in program" + ex.getMessage());
}
Office 365 ile EWS için OAuth Desteği
Aspose.Email API, Office 365 ile Exchange Web Service (EWS) desteği sağlar. API’nin EWSClient arayüz, sağlayan aşırı yükleme metodunu sunar OAuthNetworkCredential OAuth üzerinden Exchange hesabına erişmek için girdi olarak. Kullanıcının bu işlemin çalışması için Authority, Client Id, Client App Uri ve Resource parametrelerini sağlaması gerekir. Aşağıdaki kod bölümü, Office 365 ile EWS için OAuth Desteğini gösterir.
// token provider
/*ITokenProvider provider = new ITokenProvider() {
@Override
public void dispose() {
}
@Override
public OAuthToken getAccessToken(boolean ignoreExistingToken) {
return null;
}
@Override
public OAuthToken getAccessToken() {
return null;
}
};
NetworkCredential credentials = new OAuthNetworkCredential(provider);*/
// accessToken
NetworkCredential credentials = new OAuthNetworkCredential("accessToken");
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", credentials);
client.listMessages();
Exchange İstemcilerinde Günlükleme Desteği
Aspose.Email API, Exchange Web Service istemcisi için günlükleme özelliği sağlar.
EWS İstemcisi için Günlükleme
client.setLogFileName("logs/ews");
// OR
EWSClient.setCommonLogFileName("logs/ews");
EWS İsteklerine Başlık Ekleme
Aspose.Email API, Exchange isteklerine başlık eklemenize olanak tanır. Bu, farklı amaçlar için kullanılabilecek çeşitli başlıkları EWS isteklerine eklemek için kullanılabilir. Örneğin, Exchange sunucusundaki kısıtlama sorunlarını yönetmek için kullanılan X-AnchorMailbox başlığını eklemek bir örnektir. Aşağıdaki kod bölümünde gösterildiği gibi, IEWSClient’ın addHeader yöntemi, EWS isteklerine başlık eklemek için kullanılır.
final IEWSClient client = EWSClient.getEWSClient("exchange.domain.com/ews/Exchange.asmx", "username", "password", "");
try {
client.addHeader("X-AnchorMailbox", "username@domain.com");
ExchangeMessageInfoCollection messageInfoCol = client.listMessages(client.getMailboxInfo().getInboxUri());
} finally {
client.dispose();
}
İstemci İstek Kimliğini Başlıkta Döndür
Bu return-client-request-id başlık istek içinde gönderilir ve sunucu tarafından belirlemek için kullanılır client-request-id istemci tarafından belirtilen başlık, sunucu yanıtında döndürülmelidir. Bu işlemde aşağıdaki metodlar kullanılır:
- getReturnClientRequestId()
- setReturnClientRequestId(boolean değer) - İstemcinin sunucu tarafının istek kimliğini döndürmesini gerekip gerektirmediğini belirtmek için bir bayrak al veya ayarla.
try (IEWSClient client = createEWSClient())
{
// Client will create random id and pass it to the server.
// The server should include this id in request-id header of all responses.
client.setReturnClientRequestId(true);
client.setLogFileName("ews.log");
client.getMailboxInfo();
}
Birleşik Mesajlaşma ile Çalışma
Aspose.Email, Exchange Server 2010’dan birleşik mesajlaşma bilgilerini alabilir. Şu anda desteklenen birleşik mesajlaşma, yapılandırma bilgilerini alma, giden bir aramayı başlatma, arama kimliğiyle telefon araması bilgilerini alma ve kimliğiyle bir telefon aramasını sonlandırma gibi işlemleri içerir. Aşağıdaki kod örneği, Microsoft Exchange Server 2010’dan birleşik mesajlaşma yapılandırma bilgilerini nasıl alacağınızı gösterir.
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credential);
UnifiedMessagingConfiguration umConf = client.getUMConfiguration();
Posta İpuçlarını Alma
Microsoft Exchange Server, Exchange Server 2010 ve 2013 ile birkaç yeni özellik ekledi. Bunlardan biri, kullanıcıların e-posta mesajı oluştururken posta ipuçları almasını sağlar. Bu ipuçları, e-posta gönderilmeden önce bilgi sağladıkları için çok faydalıdır. Örneğin, alıcı listesindeki bir e-posta adresi hatalıysa, adresin geçersiz olduğunu belirten bir ipucu gösterilir. Posta ipuçları ayrıca e-posta gönderilmeden önce yoklama dışı yanıtlarını görmenizi sağlar: Exchange Server (2010 & 2013), alıcılardan biri veya birkaçı yoklama dışı yanıt ayarlamışsa, e-posta oluşturulurken posta ipucu gönderir. Bu makalede gösterilen tüm özellikler için Microsoft Exchange Server 2010 Service Pack 1 gerekir. Aşağıdaki kod bölümü, bunun nasıl kullanılacağını gösterir. EWSClient Microsoft Exchange Server 2007 ve sonraki sürümlerde mevcut olan Exchange Web Services’i kullanan sınıf.
// Create instance of EWSClient class by giving credentials
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
System.out.println("Connected to Exchange server...");
// Provide mail tips options
MailAddressCollection addrColl = new MailAddressCollection();
addrColl.addMailAddress(new MailAddress("test.exchange@ex2010.local", true));
addrColl.addMailAddress(new MailAddress("invalid.recipient@ex2010.local", true));
GetMailTipsOptions options = new GetMailTipsOptions(MailAddress.to_MailAddress("administrator@ex2010.local"), addrColl, MailTipsType.All);
// Get Mail Tips
MailTips[] tips = client.getMailTips(options);
// Display information about each Mail Tip
for (MailTips tip : tips) {
// Display Out of office message, if present
if (tip.getOutOfOffice() != null) {
System.out.println("Out of office: " + tip.getOutOfOffice().getReplyBody().getMessage());
}
// Display the invalid email address in recipient, if present
if (tip.getInvalidRecipient() == true) {
System.out.println("The recipient address is invalid: " + tip.getRecipientAddress());
}
}
Exchange Taklidi
Exchange taklidi, birinin başka bir hesabı taklit ederek kendi izinleri yerine taklit edilen hesabın izinleriyle görev ve işlemler yapmasına izin verir. Delegasyonun başka kullanıcıların adına hareket etmeyi sağlaması gibi, taklit diğer kullanıcılar gibi davranmayı sağlar. Aspose.Email, Exchange Taklidini destekler. EWSClient sınıf, bu özelliği kolaylaştırmak için ImpersonateUser ve ResetImpersonation yöntemlerini sağlar.
Bu görevi gerçekleştirmek için:
- Kullanıcı 1 için ExchangeWebServiceClient’ı başlat.
- Kullanıcı 2 için ExchangeWebServiceClient’ı başlat.
- Hesaplara test mesajları ekle.
- Kimlik Taklidini Etkinleştir.
- Kimlik Taklidi Sıfırla.
Aşağıdaki kod örneği size nasıl kullanılacağını gösterir EWSClient kimlik taklit özelliğini uygulamak için sınıf.
// Create instance's of EWSClient class by giving credentials
IEWSClient client1 = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser1", "pwd", "domain");
IEWSClient client2 = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser2", "pwd", "domain");
{
String folder = "Drafts";
try {
for (ExchangeMessageInfo messageInfo : (Iterable<ExchangeMessageInfo>) client1.listMessages(folder))
client1.deleteItem(messageInfo.getUniqueUri(), DeletionOptions.getDeletePermanently());
String subj1 = "NETWORKNET_33354 User User1";
client1.appendMessage(folder, new MailMessage("User1@exchange.conholdate.local", "To@aspsoe.com", subj1, ""));
for (ExchangeMessageInfo messageInfo : (Iterable<ExchangeMessageInfo>) client2.listMessages(folder))
client2.deleteItem(messageInfo.getUniqueUri(), DeletionOptions.getDeletePermanently());
String subj2 = "NETWORKNET_33354 User User2";
client2.appendMessage(folder, new MailMessage("User2@exchange.conholdate.local", "To@aspose.com", subj2, ""));
ExchangeMessageInfoCollection messInfoColl = client1.listMessages(folder);
// Assert.AreEqual(1, messInfoColl.Count);
// Assert.AreEqual(subj1, messInfoColl[0].Subject);
client1.impersonateUser(ItemChoice.PrimarySmtpAddress, "User2@exchange.conholdate.local");
ExchangeMessageInfoCollection messInfoColl1 = client1.listMessages(folder);
// Assert.AreEqual(1, messInfoColl1.Count);
// Assert.AreEqual(subj2, messInfoColl1[0].Subject);
client1.resetImpersonation();
ExchangeMessageInfoCollection messInfoColl2 = client1.listMessages(folder);
// Assert.AreEqual(1, messInfoColl2.Count);
// Assert.AreEqual(subj1, messInfoColl2[0].Subject);
} finally {
try {
for (ExchangeMessageInfo messageInfo : (Iterable<ExchangeMessageInfo>) client1.listMessages(folder))
client1.deleteItem(messageInfo.getUniqueUri(), DeletionOptions.getDeletePermanently());
for (ExchangeMessageInfo messageInfo : (Iterable<ExchangeMessageInfo>) client2.listMessages(folder))
client2.deleteItem(messageInfo.getUniqueUri(), DeletionOptions.getDeletePermanently());
} catch (java.lang.RuntimeException e) {
}
}
}
EWS Kullanarak Otomatik Keşif Özelliği
Aspose.Email API, EWS İstemcisi kullanarak Exchange Server ayarlarını keşfetmenizi sağlar.
AutodiscoverService svc = new AutodiscoverService();
svc.setCredentials(new NetworkCredential(email, password));
IGenericDictionary</* UserSettingName */Integer, Object> userSettings = svc.getUserSettings(email, UserSettingName.ExternalEwsUrl).getSettings();
String ewsUrl = (String) userSettings.get_Item(UserSettingName.ExternalEwsUrl);
System.out.println("Auto discovered EWS Url: " + ewsUrl);
Exchange Server İşlemine PST Geri Yüklemeyi İptal Et
Aspose.Email API, bir PST dosyasını Exchange Server’a geri yüklemenizi sağlar. Ancak, işlem büyük boyutlu bir PST dosyası nedeniyle uzun sürüyorsa, işlemi iptal etmek için bir kriter belirtmeniz gerekebilir. Bu, aşağıdaki örnek kodda gösterildiği gibi API kullanılarak gerçekleştirilebilir.
final IEWSClient client = EWSClient.getEWSClient("https://exchange.office365.com/ews/exchange.asmx", "username", "password");
try {
final long startTime = System.currentTimeMillis();
final AtomicInteger processedItems = new AtomicInteger(0);
final long S15 = 15 * 1000;
BeforeItemCallback callback = new BeforeItemCallback() {
public void invoke(ItemCallbackArgs item) {
if (System.currentTimeMillis() - startTime > S15) {
throw new AbortRestoreException();
}
processedItems.incrementAndGet();
}
};
try {
// create a test pst and add some test messages to it
PersonalStorage pst = PersonalStorage.create(new ByteArrayOutputStream(), FileFormatVersion.Unicode);
FolderInfo folder = pst.getRootFolder().addSubFolder("My test folder");
for (int i = 0; i < 20; i++) {
MapiMessage message = new MapiMessage("from@gmail.com", "to@gmail.com", "subj", "body");
folder.addMessage(message);
}
RestoreSettings rs = new RestoreSettings();
rs.setBeforeItemCallback(callback);
// now restore the PST with callback
client.restore(pst, rs);
System.out.println("Success!");
} catch (AbortRestoreException e) {
System.out.println("Timeout! " + processedItems.get());
}
} finally {
client.dispose();
}