メールメッセージ高度管理

MHTML ファイルで情報をカスタム順序で表示

この rendering_headers プロパティ( MhtSaveOptions クラスはレンダリングに使用されるヘッダーのリストを返します。ヘッダーに値を追加してください MhtTemplateName クラス。ヘッダーが追加される順序が出力ファイルでの情報表示順序を決定します。

以下のコードスニペットは同一メッセージを3回保存します:デフォルトのヘッダー順、カスタムヘッダー順、全く異なるヘッダーセットで。

import aspose.email as ae

eml = ae.MailMessage.load(data_dir + "Attachments.eml")
options = ae.MhtSaveOptions()

eml.save(data_dir + "CustomOrderOfInformationInMHTML_1.mhtml", options)

options.rendering_headers.append(ae.MhtTemplateName.FROM)
options.rendering_headers.append(ae.MhtTemplateName.SUBJECT)
options.rendering_headers.append(ae.MhtTemplateName.TO)
options.rendering_headers.append(ae.MhtTemplateName.SENT)

eml.save(data_dir + "CustomOrderOfInformationInMHTML_2.mhtml", options)

options.rendering_headers.clear()
options.rendering_headers.append(ae.MhtTemplateName.ATTACHMENTS)
options.rendering_headers.append(ae.MhtTemplateName.CC)
options.rendering_headers.append(ae.MhtTemplateName.SUBJECT)

eml.save(data_dir + "CustomOrderOfInformationInMHTML_3.mhtml", options)

MHTML で全ヘッダーを保存

この save_all_headers プロパティ( MhtSaveOptions クラスはメッセージのすべてのヘッダーを出力 MHTML ファイルに書き込むかどうかを定義します。以下のコードスニペットはすべてのヘッダーを保存する方法を示しています:

import aspose.email as ae

eml = ae.MailMessage.load(data_dir + "message.eml")

save_options = ae.MhtSaveOptions()
save_options.save_all_headers = True

eml.save(data_dir + "message.mhtml", save_options)

EML メッセージから前文と後文を取得

メールメッセージは本文の前(前文)や後(後文)にプレーンテキストの隠し情報を含むことがあります。これは通常、受信者がメール本文を読む前後に提供される追加情報やコンテキストです。この情報は preamble および epilogue のプロパティ MailMessage クラス。

両方のプロパティは文字列で読み書き可能であり、作成するメッセージの前文(preamble)と後文(epilogue)を設定する際にも使用できます。以下のコードスニペットは前文と後文のテキスト取得方法を示しています:

import aspose.email as ae

eml = ae.MailMessage.load(data_dir + "message.eml")

# Get the preamble text
print("Preamble: " + str(eml.preamble))

# Get the epilogue text
print("Epilogue: " + str(eml.epilogue))

MDN と既読通知を使用したメール追跡

Aspose.Email は Message Disposition Notification (MDN) を通じたメール追跡をサポートします。これは開封確認を要求し、必要な情報を作成することで実現されます。

  • この read_receipt_to プロパティ( MailMessage クラスは開封確認アドレスを取得または設定します。これは MailAddressCollection、複数のアドレスを追加できます。
  • この create_read_receipt メソッドは受信メッセージの開封確認を構築します。
  • この read_receipt_requested プロパティ( MapiMessage クラスは Outlook メッセージの開封確認が要求されているかどうかを取得または設定します。

以下のコードスニペットは、Aspose.Email を使用してメールを追跡する方法を示しています:

import aspose.email as ae
from aspose.email.clients.smtp import SmtpClient
from aspose.email.mapi import MapiMessage, MapiConversionOptions

client = SmtpClient("smtp.server.com", 587, "username", "password")

# Send a message with the requested read receipt
mail_message = ae.MailMessage("from@domain.com", "to@domain.com", "test MDN",
                              "This is a test message with read receipt requested")

read_receipt_addresses = ae.MailAddressCollection()
read_receipt_addresses.append(ae.MailAddress("from@domain.com"))
mail_message.read_receipt_to = read_receipt_addresses

client.send(mail_message)

# Several ReadReceiptTo addresses can be added to the collection
read_receipt_addresses.append(ae.MailAddress("another@domain.com"))
mail_message.read_receipt_to = read_receipt_addresses
client.send(mail_message)

# On the recipient side: check the request, then create and send the read receipt
eml_mdn = ae.MailMessage.load(data_dir + "received.eml")
if len(eml_mdn.read_receipt_to) > 0:
    client.send(eml_mdn.create_read_receipt("to@domain.com", None))

# Create a MapiMessage with a requested read receipt
mapi_message = MapiMessage("from@domain.com", "to@domain.com", "test MDN",
                           "This is a read requested mapiMessage")
mapi_message.read_receipt_requested = True

# Create a MailMessage with a requested read receipt and convert it to MapiMessage
mapi_message = MapiMessage.from_mail_message(mail_message, MapiConversionOptions.unicode_format)