ユーティリティ機能 - SMTP クライアント
Contents
[
Hide
]
SMTP クライアントを使用した拡張サーバーの一覧表示
Aspose.Email SmtpClient サーバーがサポートする IDLE、UNSELECT、QUOTA などの拡張機能を取得できます。この機能は、特定の機能をクライアントで使用する前に拡張の利用可否を確認するのに役立ちます。 getCapabilities() このメソッドは、サポートされている拡張タイプを文字列配列として返します。
サーバー拡張機能の取得
以下のコードスニペットは、サーバー拡張機能を取得する方法を示しています。
// 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 クラスは、メッセージに署名して保存したり、次のものを使用して送信したりするために使用できます。 SmtpClient.
Aspose.Email for Java API は暗号化機能に Bouncy Castle を使用していることに注意してください。
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);
分離証明書オプションの使用
Web ベースのメールクライアントは署名メッセージの本文を表示できないことがあります。送信前に証明書を分離することで対処できます。オーバーロードされたメソッドの分離フラグは attachSignature これを実現するには使用できます。true に設定すると、証明書はメールから分離されます。Web ベースのクライアントで署名メッセージ本文を表示するには、以下を作成する必要があります。 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);