MailMessageGetHtmlAndRelatedFilesInMemory Method
Gets HTML body with references to all inline attachments being replaced with user-defined indexed paths.

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public string GetHtmlAndRelatedFilesInMemory(
	string virtualPathPrefix
)

Parameters

virtualPathPrefix
Type: SystemString
The prefix to prepend to each inline attachment index.

Return Value

Type: String
The value of BodyHtmlText property with inline attachment CIDs replaced with user-defined paths.
Exceptions
ExceptionCondition
MailBeeInvalidArgumentExceptionvirtualPathPrefix is a null reference (Nothing in Visual Basic).
Remarks

This method is useful if you want to store inline attachments on an external storage or in database (i.e. not on the local filesystem). It does not save anything to disk, just replaces content-id references in the HTML body with a provided path and auto-incrementing index. However, for each inline attachment in Attachments collection, its SavedAs value is still set (you can use it to find out which value was assigned to each particular inline attachment). Non-inline attachments are not touched and their SavedAs remains an empty string.

You can then access binary content of each inline attachment with GetData method.

This method is a shortcut for GetHtmlAndSaveRelatedFiles(virtualPathPrefix, VirtualMappingType.StaticInMemory, MessageFolderBehavior.DoNotCreate).

Examples
This sample loads an e-mail from a file (you can load it from a mail server or elsewhere), replaces CIDs and then processes inline attachments. It's assumed you'll provide your own implementation of this processing (e.g. uploading files to a cloud storage or CDN).
using System;
using MailBee.Mime;

class Sample
{
    static void UploadToExternalStorage(string webPath, byte[] bytes)
    {
        // This method must upload 'bytes' to some location which is also visible via web as 'webPath'.
    }

    static void Main(string[] args)
    {
        // Load the message from file.
        MailMessage msg = new MailMessage();
        msg.LoadMessage(@"C:\Temp\test.eml");

        // You'll then pass 'body' value to some kind of a browser or webview control.
        // 'body' will have links like <IMG SRC="cid:my_first_img"> and <IMG SRC="cid:my_second_img">
        // look like <IMG SRC="https://domain.com/attach_1"> and <IMG SRC="https://domain.com/attach_2">
        string body = msg.GetHtmlAndRelatedFilesInMemory("https://domain.com/attach_");

        foreach (Attachment attach in msg.Attachments)
        {
            if (!string.IsNullOrEmpty(attach.SavedAs))
            {
                string webPath = attach.SavedAs; // e.g. https://domain.com/attach_1
                byte[] bytes = attach.GetData();

                UploadToExternalStorage(webPath, bytes);
            }
        }
    }
}
See Also