I have an issue while saving data to EML using the Aspose.Email for .NET API. The email body (body type = HTML) and attachments are set and displayed correctly as long as the images are present on the physical drive. However, when the images are deleted or removed from the temporary folder, the email no longer displays the body images.
Is there any solution for this?
Thank you for contacting Aspose.Email support.
-
could you share a code example of how you create and save messages in EML format?
-
at what point in the application’s operation do you delete/move images from the temporary folder?
-
in what method (in which application) do you notice that the body isn’t displaying images?
A detailed description of the process will help us understand your issue and offer a solution.
Code Example:
AsposeMApi.MapiMessage mailMessage = new AsposeMApi.MapiMessage();
mailMessage.SenderEmailAddress = senderEmail;
mailMessage.SenderName = senderName;
BodyContentType contentType = BodyContentType.PlainText;
if (Subject.BodyType == 2) contentType = BodyContentType.Html;
else if (Subject.BodyType == 3) contentType = BodyContentType.Rtf;
int m_importance = emlFields.Importance;
MapiImportance importance = MapiImportance.Normal;
if (m_importance == 1) importance = MapiImportance.High;
else if (m_importance == 3) importance = MapiImportance.Low;
mailMessage.SetProperty(new MapiProperty(MapiPropertyTag.PR_IMPORTANCE, BitConverter.GetBytes((int)importance)));
//for attachments
foreach (var filePath in emlFields.Attachment)
{
try
{
byte[] fileBytes = File.ReadAllBytes(filePath);
string fileName = Path.GetFileName(filePath);
mailMessage.Attachments.Add(fileName, fileBytes);
}
}
mailMessage.Save(EmlfilePath, SaveOptions.DefaultEml);
HTML BODY EXAMPLE :
Sie finden Ihr Warum verstecken Sie ihn in einem Möbelstück? Oder ihr ihn bequem mit der Sie fernsehen MonLines myTVLift!
Individuelle Halterungskonzepte ist MonLines Spezialis gibt, spezielle Kundenwunsch MonLines!
Hello @kumarpiyush01,
In your current HTML body example, the HTML contains paths like:
<img src="C:\Temp\Body1491C.gif">
This means the email is linking to images on the local disk, not embedding them into the message. So once those files are removed, the images disappear.
Instead of manually creating the message and attaching files, you can let Aspose.Email for .NET handle this automatically by loading the HTML with resources.
Here is how you can adapt your code:
var htmlloadOptions = new HtmlLoadOptions
{
PathToResources = @"C:\Temp", // folder where your images are stored
ShouldAddPlainTextView = true
};
var mailMessage = MapiMessage.Load(@"body_content.html", htmlloadOptions);
mailMessage.SetProperty(new MapiProperty(MapiPropertyTag.PR_IMPORTANCE, BitConverter.GetBytes((int)importance)));
mailMessage.SenderEmailAddress = senderEmail;
mailMessage.SenderName = senderName;
mailMessage.Subject = "New message from HTML";
// Save the message in EML format
mailMessage.Save(EmlfilePath, SaveOptions.DefaultEml);
PathToResourcestells Aspose.Email where to find the images referenced in your HTML- During loading, the library automatically embeds those images as inline resources (CID)
- The HTML is updated internally to reference embedded images instead of file paths
As a result, the final .eml file becomes self-contained, and images will still display even after the original files are deleted.
Thank you.