Java에서 메일 서비스 클라이언트 개요
버전 26.10부터 Aspose.Email for Java는 클라우드 메일 서비스 및 메일 프로토콜용 클라이언트를 포함합니다, 그리고 UnifiedMailClient, 이들을 기반으로 작동하는 단일 API입니다. 이 페이지에서는 클라이언트를 나열하고, 기존 API와의 관계를 설명하며, 사용 방법을 보여줍니다.
사용 가능한 클라이언트
모든 클라이언트는 빌더로 생성되며 구현합니다 java.io.Closeable.
| 서비스 | 클라이언트 | 패키지 | 연결 | |—|—|—|—| | IMAP | ImapClient | com.aspose.email.services.inetmail.client | 메일 프로토콜 라이브러리 | | SMTP | SmtpClient | com.aspose.email.services.inetmail.client | 메일 프로토콜 라이브러리 | | POP3 | Pop3Client | com.aspose.email.services.inetmail.client | 메일 프로토콜 라이브러리 | | SendGrid | SendGridClient | com.aspose.email.services.sendgrid.client | HTTP | | Mailgun | MailgunClient | com.aspose.email.services.mailgun.client | HTTP | | Amazon SES | SesClient | com.aspose.email.services.ses.client | HTTP | | Gmail | GmailClient | com.aspose.email.services.google.mail.client | HTTP | | Google Calendar | CalendarClient | com.aspose.email.services.google.calendar.client | HTTP | | Google People | PeopleClient | com.aspose.email.services.google.people.client | HTTP | | Microsoft Graph | MsGraphClient | com.aspose.email.services.msgraph.client | HTTP | | Exchange EWS | EwsClient | com.aspose.email.services.ews.client | HTTP |
HTTP를 통해 연결하는 클라이언트는 특정 HTTP 라이브러리에 종속되지 않습니다. 선택 방법은 메일 서비스용 HTTP 클라이언트.
서비스 클라이언트와 기존 API
서비스 클라이언트는 com.aspose.email 패키지, 예를 들어 ImapClient, SmtpClient, Pop3Client, EWSClient, GmailClient 및 GraphClient. 이러한 클래스는 계속 사용할 수 있으며, 이 가이드의 자체 섹션에 설명되어 있습니다.
두 클래스 집합은 서로 다른 데이터 유형을 사용합니다:
- 서비스 클라이언트는 예를 들어
GraphMessageMicrosoft Graph용. UnifiedMailClientAspose.Email 유형과 함께 작동합니다: MailMessage, Appointment, VCardContact 및 MapiTask.
com.aspose.email, 예를 들어 ImapClient 및 GmailClient. 대신 명시적 import를 사용하십시오. import com.aspose.email.*, 그렇지 않으면 컴파일러가 잘못된 클래스를 선택하거나 모호한 참조를 보고할 수 있습니다.
UnifiedMailClient의 기능
UnifiedMailClient 각 서비스에 공급자를 통해 도달합니다. 모든 서비스가 모든 작업을 지원하는 것은 아닙니다:
| Provider | Service | Send | Read | Calendar | Contacts | Tasks | |—|—|—|—|—|—|—| | MsGraphProvider | Microsoft Graph | 예 | 예 | 예 | 예 | 예 | | ExchangeEwsProvider | Exchange EWS | 예 | 예 | 예 | 예 | 예 | | GoogleProvider | Gmail, Google Calendar, Google People | 예 | 예 | 예 | 예 | 아니오 | | InetMailProvider | SMTP 및 IMAP | 예 | 예 | 아니오 | 아니오 | 아니오 | | SendGridProvider | SendGrid | 예 | 아니오 | 아니오 | 아니오 | 아니오 | | MailgunProvider | Mailgun | 예 | 아니오 | 아니오 | 아니오 | 아니오 | | AmazonSesProvider | Amazon SES | 예 | 아니오 | 아니오 | 아니오 | 아니오 |
InetMailProvider IMAP을 통해 메시지를 읽습니다. POP3는 독립형 Pop3Client.
런타임에 기능을 확인하려면 호출하십시오 supports 값과 함께 UnifiedCapability 열거형. 제공자가 지원하지 않는 기능에 접근하면 예를 들어 calendar() on SendGridProvider, throws UnsupportedCapabilityException.
필요 사항
클라이언트는 Aspose.Email for Java 26.10 이상 및 Java 8 이상이 필요합니다. 추가 요구 사항은 클라이언트에 따라 다릅니다:
- HTTP를 통해 연결하는 클라이언트는 추가 라이브러리 없이 작동합니다. 다른 HTTP 라이브러리 사용 방법은 메일 서비스용 HTTP 클라이언트.
ImapClient,SmtpClient및Pop3Client클래스패스에 Jakarta Mail 또는 JavaMail이 필요합니다. 자세한 내용은 메일 프로토콜 라이브러리 설정.
서비스 클라이언트 사용
다음 코드 샘플은 Microsoft Entra ID에 등록된 애플리케이션으로 Microsoft Graph에 연결하고 사서함에서 다섯 개 메시지의 제목을 나열합니다:
import com.aspose.email.services.msgraph.api.QueryOptions;
import com.aspose.email.services.msgraph.auth.ClientCredentialsTokenProvider;
import com.aspose.email.services.msgraph.client.MsGraphClient;
import com.aspose.email.services.msgraph.model.GraphMessage;
import java.util.List;
try (MsGraphClient graph = MsGraphClient.builder()
.tokenProvider(new ClientCredentialsTokenProvider("tenant-id", "client-id", "client-secret"))
.build()) {
List<GraphMessage> messages = graph.users("user@example.com").messages()
.list(QueryOptions.builder().top(5).build());
for (GraphMessage message : messages) {
System.out.println(message.getSubject());
}
}
UnifiedMailClient 사용
다음 코드 샘플은 동일한 사서함을 통해 읽습니다. UnifiedMailClient. 다른 서비스와 작업하려면 제공자를 변경하십시오:
import com.aspose.email.services.bridge.common.model.MailMessageInfo;
import com.aspose.email.services.bridge.msgraph.provider.MsGraphProvider;
import com.aspose.email.services.unified.UnifiedMailClient;
import com.aspose.ext.http.HttpClientAutoDetect;
import com.aspose.ext.http.IHttpClient;
import java.util.List;
try (IHttpClient http = HttpClientAutoDetect.detect()) {
MsGraphProvider provider = MsGraphProvider.builder()
.httpClient(http)
.tenantId("tenant-id")
.clientId("client-id")
.clientSecret("client-secret")
.userPrincipalName("user@example.com")
.build();
try (UnifiedMailClient client = UnifiedMailClient.builder().provider(provider).build()) {
List<MailMessageInfo> messages = client.mail().inbox().list(5);
for (MailMessageInfo message : messages) {
System.out.println(message.getSubject());
}
}
}
로그 활성화
로깅은 선택 사항입니다. 클라이언트는 로깅 라이브러리가 없어도 작동하며 로그에 아무 것도 기록하지 않습니다.
로그 출력을 확인하려면 클래스패스에 SLF4J와 로거 구현을 추가하십시오. 로거 이름은 다음으로 시작합니다. com.aspose.email 또는 com.aspose.ext.http.