เริ่มต้นอย่างรวดเร็ว

เริ่มต้นอย่างรวดเร็ว

เริ่มต้นอย่างรวดเร็ว

หน้านี้มีตัวอย่างอิสระสามตัวที่คุณสามารถคัดลอกไปยังโครงการคอนโซล .NET 8 และเรียกใช้ได้ทันที. ตัวอย่างแต่ละตัวครอบคลุมกระบวนการทำงานหลักของไลบรารี

ข้อกำหนดเบื้องต้น

dotnet new console -n EmailDemo
cd EmailDemo
dotnet add package Aspose.Email.Foss

ตัวอย่าง 1 — อ่านไฟล์ MSG

เปิดไฟล์ Outlook .msg แล้วพิมพ์หัวเรื่อง ผู้ส่ง ผู้รับ และไฟล์แนบ

using System.IO;
using Aspose.Email.Foss.Msg;

using var stream = File.OpenRead("sample.msg");
var message = MapiMessage.FromStream(stream);

Console.WriteLine($"Subject: {message.Subject}");
Console.WriteLine($"From: {message.SenderName} <{message.SenderEmailAddress}>");

foreach (var recipient in message.Recipients)
    Console.WriteLine($"  To: {recipient.DisplayName} <{recipient.EmailAddress}>");

foreach (var attachment in message.Attachments)
    Console.WriteLine($"  Attachment: {attachment.Filename} ({attachment.MimeType})");

ตัวอย่าง 2 — สร้างและบันทึกข้อความ

สร้างอีเมลที่สมบูรณ์พร้อมผู้ส่ง ผู้รับ และไฟล์แนบ แล้วบันทึกเป็นไฟล์ MSG.

using System.IO;
using Aspose.Email.Foss.Msg;

var message = MapiMessage.Create("Quarterly Update", "Please see the attached report.");
message.SenderName = "Alice";
message.SenderEmailAddress = "alice@example.com";

message.AddRecipient("bob@example.com", "Bob");
message.AddRecipient("carol@example.com", "Carol", MapiMessage.RecipientTypeCc);

message.AddAttachment("report.pdf", File.ReadAllBytes("report.pdf"), "application/pdf");

message.Save("quarterly-update.msg");

กรุณาให้ข้อความที่ต้องการแปลจากภาษาอังกฤษเป็นภาษาไทยเพื่อดำเนินการต่อได้ค่ะ.

using var msg = MapiMessage.FromFile("quarterly-update.msg");
Console.WriteLine(msg.Subject);           // Quarterly Update
Console.WriteLine(msg.Attachments.Count); // 1

ตัวอย่าง 3 — แปลงระหว่าง EML และ MSG

โหลดไฟล์มาตรฐาน .eml (RFC 5322 / MIME) แล้วบันทึกเป็น Outlook MSG จากนั้นแปลงกลับ

using System.IO;
using Aspose.Email.Foss.Msg;

// EML → MSG
using var emlInput = File.OpenRead("incoming.eml");
var message = MapiMessage.LoadFromEml(emlInput);
message.Save("incoming.msg");

// MSG → EML (round-trip)
message.SaveToEml("roundtrip.eml");

หัวเรื่อง, เนื้อหา, เนื้อหา HTML, ผู้ส่ง, ผู้รับ, และไฟล์แนบทั้งหมดจะถูกเก็บรักษาไว้ตลอดการเดินทางรอบ EML → MSG → EML.


ขั้นตอนต่อไป

 ภาษาไทย