Python を使用して Outlook 電子メールを TIFF に変換する方法

この小さなトピックでは、環境をセットアップするための詳細な手順に従って、Python を使用して Outlook Email を TIFF に変換する方法に焦点を当てます。 EML を TIFF Python ベースの API に変換するために、Windows や Linux などのオペレーティング システムの Python 構成環境で、シンプルな API インターフェイスを提供する API を使用できます。

Python を使用して Outlook 電子メールを TIFF に変換する手順

  1. Python で電子メールを TIFF に変換するには、アプリケーションで .NET 経由で Aspose.Email for Python を使用.NET 経由の Python 用 Aspose.Words に環境を設定します
  2. MailMessage クラス オブジェクトを作成して、MSG または EML 形式の電子メール ファイルを読み込みます
  3. アクセスした電子メール (EML/MSG) ファイルをメモリ ストリームに MHTML 形式で保存する
  4. LoadFormat を MHTML に設定し、Document クラス オブジェクトをインスタンス化して、前の手順で作成した中間 MHTML をロードします。
  5. Python で save メソッドを使用して、EML から TIFF への変換を実行します。

前述の手順を実行し、Python の単純なコードを使用して、電子メールから TIFF へのコンバーター アプリケーションを開発できます。まず、MailMessage クラスのインスタンスを使用してディスクからソース MSG または EML ファイルをロードします。その後、メモリ ストリーム内の中間 MHTML ファイルに保存します。その後、Document クラスのインスタンスを使用して、MHTML がロードされ、Save メソッドを使用してディスクに TIFF ファイルとして保存されます。

Python を使用して Outlook 電子メールを TIFF に変換するコード

import aspose.email as ae
import aspose.words as aw
import io
# Path to load the source files
srcFilePath = "Y://TestData//"
# Load the license in your application for converting MSG/EML to MHTML
emlFileLicense = ae.License()
emlFileLicense.set_license(srcFilePath + "Conholdate.Total.Product.Family.lic")
# Load the Aspose.Words license in your application for converting MHTML to TIFF
wordsFileLicense = aw.License()
wordsFileLicense.set_license(srcFilePath + "Conholdate.Total.Product.Family.lic")
# Open the source MSG or EML file from the disk
srcMessageFile = ae.MailMessage.load(srcFilePath + "Message.msg")
# Save the document to an intermediate stream as an MHTML with default options
mhtml_int_Stream = io.BytesIO()
# Save the email to stream
srcMessageFile.save(mhtml_int_Stream, ae.SaveOptions.default_mhtml)
# seek the position of the Memory stream to the brginning
mhtml_int_Stream.seek(0)
# Set the LoadOptions to Load the Mhtml
loadOptions = aw.loading.LoadOptions()
loadOptions.load_format = aw.LoadFormat.MHTML
# Initialize the Document class object to load the intermediate MTHML from MemoryStream
mhtmlToTiffDocument = aw.Document(mhtml_int_Stream, loadOptions)
# Close the MHTML stream to avoid a memory leak
mhtml_int_Stream.close()
# Save the MHTML to TIFF using Python
mhtmlToTiffDocument.save(srcFilePath + "SaveEmailAsDoc.tiff")
print ("EML converted to Tiff file")

EML を TIFF Python ベースの API に変換するために、単純な機能を公開し、明確に定義された手順を上記の例で参照しました。これは複数のステップからなるプロセスであり、最初のステップでは、メモリ ストリーム内で EML または MSG ファイルを中間 MHTML ファイルに変換します。最後のステップでは、中間の MHTML が TIFF ファイルとしてレンダリングされ、ディスクに保存されます。

この例では、Python ベースの API を使用して Outlook 電子メールを TIFF に変換する方法について学びました。 Mapi 連絡先の作成に興味がある場合は、Python を使用して Mapi 連絡先を作成する方法 の記事を参照してください。

 日本語