Class InlineHtmlBuilder
- Namespace
- Wolfgang.Extensions.Mail
- Assembly
- Wolfgang.Extensions.Mail.dll
A builder for creating HTML AlternateView instances with inline embedded images. Manages LinkedResource creation and Content-ID wiring automatically.
public sealed class InlineHtmlBuilder
- Inheritance
-
InlineHtmlBuilder
- Inherited Members
Examples
using var message = new MailMessage("from@example.com", "to@example.com");
var builder = new InlineHtmlBuilder()
.Html("<h1>Report</h1><img src='cid:{0}' />")
.EmbedImage("chart.png");
message.AlternateViews.Add(builder.Build());
Methods
Build()
Builds the AlternateView with all embedded images wired up.
The HTML template placeholders ({0}, {1}, etc.) are replaced with
the generated Content-IDs.
public AlternateView Build()
Returns
- AlternateView
An AlternateView containing the HTML and all linked resources.
Exceptions
- InvalidOperationException
No HTML template has been set via Html(string).
EmbedImage(byte[], string, string?)
Embeds an image from a byte array as a LinkedResource.
public InlineHtmlBuilder EmbedImage(byte[] imageBytes, string fileName, string? contentType = null)
Parameters
imageBytesbyte[]The image content as a byte array.
fileNamestringA file name used for content type inference (e.g.,
"chart.png").contentTypestringOptional explicit content type. When
null, inferred fromfileName.
Returns
- InlineHtmlBuilder
This builder instance for chaining.
Exceptions
- ArgumentNullException
imageBytesis null.- ArgumentNullException
fileNameis null.
EmbedImage(Stream, string, string?)
Embeds an image from a Stream as a LinkedResource. The stream content is copied; the original stream is not modified.
public InlineHtmlBuilder EmbedImage(Stream imageStream, string fileName, string? contentType = null)
Parameters
imageStreamStreamThe stream containing the image data.
fileNamestringA file name used for content type inference (e.g.,
"logo.png").contentTypestringOptional explicit content type. When
null, inferred fromfileName.
Returns
- InlineHtmlBuilder
This builder instance for chaining.
Exceptions
- ArgumentNullException
imageStreamis null.- ArgumentNullException
fileNameis null.
EmbedImage(string)
Embeds an image from a file path as a LinkedResource. The content type is inferred from the file extension.
public InlineHtmlBuilder EmbedImage(string filePath)
Parameters
filePathstringThe path to the image file.
Returns
- InlineHtmlBuilder
This builder instance for chaining.
Exceptions
- ArgumentNullException
filePathis null.
Html(string)
Sets the HTML template. Use {0}, {1}, etc. as placeholders for
embedded image Content-IDs, which are filled in order of EmbedImage(string) calls.
public InlineHtmlBuilder Html(string htmlTemplate)
Parameters
htmlTemplatestringThe HTML template string with
{n}placeholders for inline images.
Returns
- InlineHtmlBuilder
This builder instance for chaining.
Exceptions
- ArgumentNullException
htmlTemplateis null.