유틸리티 기능 - SMTP 클라이언트

SMTP 클라이언트를 사용한 확장 서버 나열

Aspose.Email SmtpClient 서버가 지원하는 IDLE, UNSELECT, QUOTA 등과 같은 확장 기능을 검색할 수 있게 해줍니다. 이는 특정 기능을 사용하기 전에 확장의 가용성을 판단하는 데 도움이 됩니다. 해당 getCapabilities() method는 지원되는 확장 유형을 문자열 배열 형태로 반환합니다.

서버 확장 기능 검색

다음 코드 스니펫은 서버 확장 기능을 검색하는 방법을 보여줍니다.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java

SmtpClient client = new SmtpClient("smtp.gmail.com",587,"username","password");
client.setSecurityOptions(SecurityOptions.Auto);
String[] caps = client.getCapabilities();
for (String str:caps)
	System.out.println(str);

서명된 메시지 작업

Aspose.Email API는 인증서를 사용해 서명된 메시지를 생성하는 기능을 제공합니다. 해당 attachSignature 메서드 MailMessage class는 메시지를 서명하여 저장하거나 다음을 사용해 전송할 수 있습니다 SmtpClient.

Bouncy Castle Maven 의존성

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.60</version>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.60</version>
</dependency>

Bouncy Castle 보안 제공자 활성화

import java.security.Security;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

if (Security.getProvider("BC") == null)
    Security.addProvider(new BouncyCastleProvider());

메시지 서명

다음 코드 스니펫은 메시지에 서명하는 방법을 보여줍니다.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java

byte[] privateCert = Files.readAllBytes(new File("sample.pfx").toPath());
byte[] publicCert = Files.readAllBytes(new File("sample.cer").toPath());

MailMessage msg = new MailMessage("userfrom@gmail.com", "userto@gmail.com", "Signed message only", "Test Body of signed message");
MailMessage signed = msg.attachSignature(privateCert, "password");
MailMessage encrypted = signed.encrypt(publicCert, "password");
MailMessage decrypted = encrypted.decrypt(privateCert, "password");
MailMessage unsigned = decrypted.removeSignature();// The original message with proper body
MapiMessage mapi = MapiMessage.fromMailMessage(unsigned);

분리된 인증서 옵션 사용

웹 기반 이메일 클라이언트는 서명된 메시지의 본문 내용을 표시하지 못할 수 있습니다. 이를 해결하려면 웹 기반 클라이언트에 보내기 전에 인증서를 분리하면 됩니다. 중첩된 메서드의 분리 플래그는 attachSignature 이를 구현하는 데 사용할 수 있습니다. true로 설정하면 인증서가 이메일에서 분리됩니다. 웹 기반 클라이언트에서 서명된 메시지 본문을 보려면 다음을 생성해야 합니다 MailMessage 분리된 서명과 함께. 다음 코드 스니펫은 분리된 인증서 옵션을 사용하는 방법을 보여줍니다.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java

MailMessage msg = new MailMessage("dr38445@gmail.com", "dr38445@gmail.com", "subject:Signed message only by AE", "body:Test Body of signed message by AE");
MailMessage signed = msg.attachSignature(privateCert, "password", true);
SmtpClient smtp = getSmtpClient(); //some test smtp client

smtp.send(signed);