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

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

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

  1. NuGet パッケージ マネージャーから Aspose.Email および Aspose.Words ライブラリをインストールする環境をセットアップします
  2. ソースの MSG または EML 形式の電子メール ファイルをロードする MailMessage クラス オブジェクトを作成します。
  3. アクセスした電子メール (EML/MSG) ファイルをストリームに MHTML 形式で保存します
  4. LoadFormat を MHTML に初期化し、Document クラス オブジェクトを作成して、前の手順で作成した中間 MHTML をロードします。
  5. C# で Save メソッドを使用すると、EML から TIFF への変換が行われます。

前述の C# Email to TIFF コンバーターの手順に従うことで、アプリケーションを開発できます。 MailMessage クラス オブジェクトを使用してディスクからソース MSG または EML ファイルをロードすることでプロセスを開始します。その後、出力を中間 MHTML ファイルとしてメモリ ストリームに保存します。次に、Document クラスのインスタンスを使用して、MHTML が読み込まれ、Save メソッドを使用して TIFF ファイルとしてディスクに保存されます。

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

using System;
using System.IO;
using Aspose.Email;
using Aspose.Words;
namespace KBEmail
{
public class EmlToTiff
{
public static void ConvertEmailToTiff()
{
string FilePath = @"C:/TestData/";
// Applying product license to convert email to Tiff
Aspose.Email.License emailTiffLicense = new Aspose.Email.License();
emailTiffLicense.SetLicense(FilePath + "Conholdate.Total.Product.Family.lic");
// Apply the product license to convert EML to TIFF
Aspose.Words.License wordsTiffLicence = new Aspose.Words.License();
wordsTiffLicence.SetLicense(FilePath + "Conholdate.Total.Product.Family.lic");
using (MemoryStream mhtStream = new MemoryStream())
{
// Open the EML or an MSG file from the disk
MailMessage srcEmlMessage = MailMessage.Load(FilePath + "Message.msg");
// Save the email to an intermediate MHTML file
srcEmlMessage.Save(mhtStream, Aspose.Email.SaveOptions.DefaultMhtml);
// Reset the Memory stream position
mhtStream.Position = 0;
// Configure the LoadOptions to set the LoadFormat to Mhtml
Aspose.Words.Loading.LoadOptions loadOptions = new Aspose.Words.Loading.LoadOptions();
loadOptions.LoadFormat = LoadFormat.Mhtml;
// Create the Document class object to access the MTHML stream
Aspose.Words.Document mhtDocument = new Aspose.Words.Document(mhtStream, loadOptions);
// Save the loaded MHTML to TIFF using C#
mhtDocument.Save(FilePath + "Saved-Aspose_out.tiff", SaveFormat.Tiff);
}
}
}
}

EML を TIFF C# に変換するために、単純な API 呼び出しと明確に定義された手順が上記の例で参照されています。これは 2 段階のプロセスで、最初の段階で EML または MSG ファイルが中間 MHTML ファイルとしてメモリ ストリームに保存されます。次に、最後のステップで、MHTML が TIFF ファイルに変換され、ディスクに保存されます。

この記事では、C# ベースの API を使用して Outlook 電子メールを TIFF に変換する方法を説明しました。 MS Outlook を使用せずに MSG ファイルを開く場合は、C#でOutlookなしでMSGファイルを開く方法 の記事を参照してください。

 日本語