<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://mail.logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=Embedding_Image_to_Email</id>
		<title>Embedding Image to Email - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://mail.logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=Embedding_Image_to_Email"/>
		<link rel="alternate" type="text/html" href="https://mail.logicwiki.co.uk/index.php?title=Embedding_Image_to_Email&amp;action=history"/>
		<updated>2026-07-04T00:10:40Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>https://mail.logicwiki.co.uk/index.php?title=Embedding_Image_to_Email&amp;diff=1746&amp;oldid=prev</id>
		<title>AliIybar at 10:16, 14 December 2018</title>
		<link rel="alternate" type="text/html" href="https://mail.logicwiki.co.uk/index.php?title=Embedding_Image_to_Email&amp;diff=1746&amp;oldid=prev"/>
				<updated>2018-12-14T10:16:47Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 10:16, 14 December 2018&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l56&quot; &gt;Line 56:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 56:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Best Example &lt;/del&gt;I &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Found &lt;/del&gt;==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== I &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;was inspired from the code I found below &lt;/ins&gt;==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre class=&amp;quot;brush:csharp;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;pre class=&amp;quot;brush:csharp;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;string body = &amp;quot;blah blah blah... body goes here with the image tag: &amp;lt;img src=\&amp;quot;cid:companyLogo\&amp;quot; width=&amp;quot;104&amp;quot; height=&amp;quot;27&amp;quot; /&amp;gt;&amp;quot;;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;string body = &amp;quot;blah blah blah... body goes here with the image tag: &amp;lt;img src=\&amp;quot;cid:companyLogo\&amp;quot; width=&amp;quot;104&amp;quot; height=&amp;quot;27&amp;quot; /&amp;gt;&amp;quot;;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>AliIybar</name></author>	</entry>

	<entry>
		<id>https://mail.logicwiki.co.uk/index.php?title=Embedding_Image_to_Email&amp;diff=1745&amp;oldid=prev</id>
		<title>AliIybar: Created page with &quot;Category:CSharp Category:ASP.NET Category:Tips  == The problem == After I'd sent an email containing image with public url as src it failed to display images in ou...&quot;</title>
		<link rel="alternate" type="text/html" href="https://mail.logicwiki.co.uk/index.php?title=Embedding_Image_to_Email&amp;diff=1745&amp;oldid=prev"/>
				<updated>2018-12-14T10:16:11Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;a href=&quot;/index.php?title=Category:CSharp&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:CSharp (page does not exist)&quot;&gt;Category:CSharp&lt;/a&gt; &lt;a href=&quot;/index.php?title=Category:ASP.NET&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:ASP.NET (page does not exist)&quot;&gt;Category:ASP.NET&lt;/a&gt; &lt;a href=&quot;/index.php?title=Category:Tips&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:Tips (page does not exist)&quot;&gt;Category:Tips&lt;/a&gt;  == The problem == After I&amp;#039;d sent an email containing image with public url as src it failed to display images in ou...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:CSharp]]&lt;br /&gt;
[[Category:ASP.NET]]&lt;br /&gt;
[[Category:Tips]]&lt;br /&gt;
&lt;br /&gt;
== The problem ==&lt;br /&gt;
After I'd sent an email containing image with public url as src it failed to display images in outlook and gmail &lt;br /&gt;
 &amp;lt;img src=&amp;quot;http://www.imagesource.com/image1.jpg&amp;quot;&amp;gt;&lt;br /&gt;
So I converted Image src to base64 in [https://www.base64-image.de/ https://www.base64-image.de/] It worked in outlook but not worked in Gmail. &lt;br /&gt;
  &amp;lt;img src=&amp;quot;data:image/png;base64,iVBORw0KGgoAAAANSUhE....&lt;br /&gt;
Finally I came to a point where embedding images to emails is the last solution. But it must be applied to templates and I had to complete this with minimum effort and minimum changes (without breaking working code) &lt;br /&gt;
== The solution ==&lt;br /&gt;
* I created a folder where Mailer app sits &lt;br /&gt;
 D:\Web\EmbeddedImages&lt;br /&gt;
* Added this folder to App.config &lt;br /&gt;
 &amp;lt;add key=&amp;quot;ImagesFolder&amp;quot; value=&amp;quot;D:\Web\EmbeddedImages&amp;quot; /&amp;gt;&lt;br /&gt;
* in the method where I send emails I added these lines&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:csharp;&amp;quot;&amp;gt;&lt;br /&gt;
MailMessage mm = new MailMessage();&lt;br /&gt;
var imagesFolder = ConfigurationManager.AppSettings[&amp;quot;ImagesFolder&amp;quot;];&lt;br /&gt;
string pattern = @&amp;quot;##IMG(.+?)##&amp;quot;;&lt;br /&gt;
MatchCollection matches = Regex.Matches(email.Body, pattern);&lt;br /&gt;
var imgId = 0;&lt;br /&gt;
var images = new List&amp;lt;LinkedResource&amp;gt;();&lt;br /&gt;
foreach (var item in matches)&lt;br /&gt;
{&lt;br /&gt;
  imgId += 1;&lt;br /&gt;
  var imgName = item.ToString().Replace(&amp;quot;##&amp;quot;, &amp;quot;&amp;quot;).Replace(&amp;quot;IMG|&amp;quot;, &amp;quot;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
  byte[] reader = File.ReadAllBytes(imagesFolder + &amp;quot;\\&amp;quot; + imgName);&lt;br /&gt;
  MemoryStream image1 = new MemoryStream(reader);&lt;br /&gt;
  LinkedResource linkedImg = new LinkedResource(image1, System.Net.Mime.MediaTypeNames.Image.Jpeg);&lt;br /&gt;
&lt;br /&gt;
  linkedImg.ContentId = &amp;quot;image&amp;quot; + imgId.ToString();&lt;br /&gt;
  linkedImg.ContentType = new System.Net.Mime.ContentType(&amp;quot;image/jpg&amp;quot;);&lt;br /&gt;
  email.Body = email.Body.Replace(item.ToString(), &amp;quot;cid:&amp;quot; + &amp;quot;image&amp;quot; + imgId.ToString());&lt;br /&gt;
  images.Add(linkedImg);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if (matches.Count &amp;gt; 0)&lt;br /&gt;
{&lt;br /&gt;
  AlternateView av1 = AlternateView.CreateAlternateViewFromString(email.Body, null, MediaTypeNames.Text.Html);&lt;br /&gt;
  foreach (var linkedResource in images)&lt;br /&gt;
  {&lt;br /&gt;
     av1.LinkedResources.Add(linkedResource);&lt;br /&gt;
  }&lt;br /&gt;
mm.AlternateViews.Add(av1);&lt;br /&gt;
}&lt;br /&gt;
mm.Body = email.Body;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Usage ===&lt;br /&gt;
# Save your image(s) to D:\Web\EmbeddedImages&amp;quot; (folder setting is in app.config of VDSCore.Mailer application)&lt;br /&gt;
# Let’s say you have a TrainingLogo.jpg save it as D:\Web\EmbeddedImages\TrainingLogo.jpg&lt;br /&gt;
# In the template change img src like &amp;lt;img src=”##IMG|TrainingLogo.jpg##”&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Best Example I Found ==&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:csharp;&amp;quot;&amp;gt;&lt;br /&gt;
string body = &amp;quot;blah blah blah... body goes here with the image tag: &amp;lt;img src=\&amp;quot;cid:companyLogo\&amp;quot; width=&amp;quot;104&amp;quot; height=&amp;quot;27&amp;quot; /&amp;gt;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
byte[] reader = File.ReadAllBytes(&amp;quot;E:\\TestImage.jpg&amp;quot;);&lt;br /&gt;
MemoryStream image1 = new MemoryStream(reader);&lt;br /&gt;
AlternateView av = AlternateView.CreateAlternateViewFromString(body, null, System.Net.Mime.MediaTypeNames.Text.Html);&lt;br /&gt;
&lt;br /&gt;
LinkedResource headerImage = new LinkedResource(image1, System.Net.Mime.MediaTypeNames.Image.Jpeg);&lt;br /&gt;
headerImage.ContentId = &amp;quot;companyLogo&amp;quot;;&lt;br /&gt;
headerImage.ContentType = new ContentType(&amp;quot;image/jpg&amp;quot;);&lt;br /&gt;
av.LinkedResources.Add(headerImage);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();&lt;br /&gt;
message.AlternateViews.Add(av);&lt;br /&gt;
message.To.Add(emailTo);&lt;br /&gt;
message.Subject = &amp;quot; Your order is being processed...&amp;quot;;&lt;br /&gt;
message.From = new System.Net.Mail.MailAddress(&amp;quot;xxx@example.com&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ContentType mimeType = new System.Net.Mime.ContentType(&amp;quot;text/html&amp;quot;);&lt;br /&gt;
AlternateView alternate = AlternateView.CreateAlternateViewFromString(body, mimeType);&lt;br /&gt;
message.AlternateViews.Add(alternate);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>AliIybar</name></author>	</entry>

	</feed>