Exchange Server'a Bağlanma
Exchange Web Service kullanarak Exchange sunucularına 2007, 2010 ve 2013 bağlanmak için Aspose.Email şu … sağlar. IEWSClient arayüz, … uygular EWSClient sınıf. EWSClient.getEWSClient metod bir … örnekleyip döndürür IEWSClient nesne, bir Exchange posta kutusu ve diğer klasörlerle ilgili işlemleri gerçekleştirmek için daha sonra kullanılır. Bu makale, … nesnelerinin nasıl örneklenebileceğini gösterir. IEWSClient.
EWS kullanarak Exchange Server’a Bağlanma
Aşağıdaki kod parçacığı, Exchange Web Service (EWS) kullanarak nasıl bağlanacağınızı gösterir.
private static IEWSClient getExchangeEWSClient() {
final String mailboxUri = "https://outlook.office365.com/ews/exchange.asmx";
final String domain = "";
final String username = "username@onmicrosoft.com";
final String password = "password";
NetworkCredential credentials = new NetworkCredential(username, password, domain);
IEWSClient client = EWSClient.getEWSClient(mailboxUri, credentials);
return client;
}
IMAP kullanarak Exchange Server’a Bağlanma
Microsoft Exchange Server, bir posta kutusundaki öğelere erişmek için IMAP protokolünü destekler. Aspose.Email’in … kullanın ImapClient IMAP protokolünü kullanarak Exchange Server’a bağlanan sınıf. Daha fazla bilgi için … ImapClient class. Öncelikle, Exchange Server’ınız için IMAP hizmetlerinin etkin olduğundan emin olun:
- Denetim Masası’nı açın.
- Yönetim Araçları’na gidin, ardından Hizmetler.
- Microsoft Exchange IMAP4 hizmetinin durumunu kontrol edin.
- Henüz çalışmıyorsa, etkinleştirin / başlatın.
Aşağıdaki kod parçacığı, IMAP protokolünü kullanarak Microsoft Exchange sunucusunun Gelen Kutusu klasöründen bağlanıp mesajları listelemeyi gösterir.
// Connect to Exchange Server using ImapClient class
ImapClient imapClient = new ImapClient("ex07sp1", "Administrator", "Evaluation1");
imapClient.setSecurityOptions(SecurityOptions.Auto);
// Select the Inbox folder
imapClient.selectFolder(ImapFolderInfo.IN_BOX);
// Get the list of messages
ImapMessageInfoCollection msgCollection = imapClient.listMessages();
for (ImapMessageInfo msgInfo : (Iterable<ImapMessageInfo>) msgCollection) {
System.out.println(msgInfo.getSubject());
}
// Disconnect from the server
imapClient.dispose();
Aşağıdaki kod parçacığı, SSL kullanımını gösterir.
public static void run() {
// Connect to Exchange Server using ImapClient class
ImapClient imapClient = new ImapClient("ex07sp1", 993, "Administrator", "Evaluation1");
imapClient.setSecurityOptions(SecurityOptions.SSLExplicit);
// Select the Inbox folder
imapClient.selectFolder(ImapFolderInfo.IN_BOX);
// Get the list of messages
ImapMessageInfoCollection msgCollection = imapClient.listMessages();
for (ImapMessageInfo msgInfo : (Iterable<ImapMessageInfo>) msgCollection) {
System.out.println(msgInfo.getSubject());
}
// Disconnect from the server
imapClient.dispose();
}
IMAP kullanarak bir Exchange sunucusuna bağlandıktan ve … aldığınızda IMapMessageInfoCollection, Aşağıdaki kod parçacığı, … kullanımını gösterir MessageInfo nesnenin belirli bir mesajı kaydetmek için sıra numarası.
// Select the Inbox folder
imapClient.selectFolder(ImapFolderInfo.IN_BOX);
// Get the list of messages
ImapMessageInfoCollection msgCollection = imapClient.listMessages();
for (ImapMessageInfo msgInfo : (Iterable<ImapMessageInfo>) msgCollection) {
// Fetch the message from inbox using its SequenceNumber from msgInfo
MailMessage message = imapClient.fetchMessage(msgInfo.getSequenceNumber());
// Save the message to disc now
message.save(dataDir + msgInfo.getSequenceNumber() + "_out.msg", SaveOptions.getDefaultMsgUnicode());
}