1

I want to embed images in my email content, for example logo. Normally in C# I add LinkedResource and refer to contentId in my email template. How can I do this in MDriven?

1 Answers1

1

Is the image data or static? Do you want the image to be included or referenced?

<img src="data:image/jpg;base64,base64-data-string here" />

Your byte array to base64 and like above.

Updated with new info that MDrivenServer now also support inline disposition of images added as attachments with contentid : https://wiki.mdriven.net/index.php/Emailing_from_an_app_using_MDrivenServer

Hans Karlsen
  • 2,275
  • 1
  • 15
  • 15
  • In the email template the image look like this Logo. To add the image in C# the AlternateView htmlView = AlternateView.CreateAlternateViewFromString(msgHtml.Body, null, "text/html"); string logopath = GetGlobalCompanyfilePath(aForetag) + HTML_MAIL_LOGO_NAME; if (File.Exists(logopath)) { LinkedResource res = new LinkedResource(logopat res.ContentLink = new Uri(logopath); res.ContentId = "Emaillogo"; htmlView.LinkedResources.Add(res); } msg.AlternateViews.Add(htmlView); – Bengt Henriksson May 26 '20 at 15:55
  • I will test the base64 solution – Bengt Henriksson May 26 '20 at 16:25
  • The generates an error. – Bengt Henriksson May 26 '20 at 16:41
  • Did new test and the base64 is there but image is broken, I use BlobToBase64. – Bengt Henriksson May 26 '20 at 17:03
  • It works only when using opendocumentreportshow. When trying to send as email body it do not work. Get error log: 2020-05-27 14:48:03,164 [113] ERROR AppCompleteGeneric.admin.LogUsage - EXCEPTION: bughuntinfo internaleval:83 es seems fineAsByteArray: Error producing Open document report bughuntinfo internaleval:83 es seems fineValue cannot be null. Parameter name: inArray vBody := self.Order.opendocumentreportasblob(Order.Viewmodels.HtmlOrderConfirmation ).asString – Bengt Henriksson May 27 '20 at 14:53
  • src="data:image/png;base64,{{%emaillogo%}}"/ will end up as src="data:image/png;base64,{{BASE64data==}}"/ -> the {{ }} destroys your data. Use src="data:image/png;base64,%emaillogo%" – Hans Karlsen May 28 '20 at 10:23
  • 1
    Now it work great, thanks MDriven for absolutely terrific support! – Bengt Henriksson Jul 02 '20 at 19:56