Using HTML file as mail body template, images are not showing - c#

I am trying to use a HTML file as mail body template. HTML file has few inline images like LOGO. Everything is fine and I am getting all contents in the HTML file upon receiving the mail, except the images.
An example below src="~/Images/logo.png" but after getting the mail, if I view source in mail client I see like below (using Google SMTP server to send mail).
Reason is pretty clear as why images are not getting displayed (due to the fact that src part is getting changed) but not sure how to avoid this.
<img title="MyCompany" class="xxxx" alt="MyCompany"
src="https://ci4.googleusercontent.com/proxy/VigKoQr9DXTS3UveuswmpxB6iEAO5rcVwSrrVUptfWGAeYQFugjcKDZxDZbB6g=s0-d-e1-ft#http://~/Images/logo.png">
Any solution for this? How can I get the actual images being displayed?
Thank You.

Here the solution!
For email template you should provide absolute url for the image.
Ex: <img src="http://ngm.nationalgeographic.com/2015/11/climate-change/which-species-will-thrive/img/12-bengal-tiger-1024.jpg" >

Related

How do I send an embedded image email without ATT00001.bin file with c#

I am able to send email via smtp with c#, whereby inserting images with LinkedResource.
The problem now is that the emails received contain ATT0000X.bin files as attachment. How do I make sure these bin files are not added in the email?
Thanks in advance!
I just had this issue while trying to embed an image to the e-mail. I had two things wrong on my code, maybe one of them is happening to you:
First I was embedding an image but didn't define any tag for it to be displayed in my Body. This was fixed by adding into my HTML the tag cid:yourContentId and then assigning that tag as the image's ContentId. That fixed the issue in outlook, but it was still showing a clip like if the e-mail had an attachment, but no place to actually see the attachment. This looks super spammy. In Outlook web you could still see the ATT00001.bin attachment.
My second mistake was not defining the ContentType of my embedded image when creating the LinkedResource. This fixed the clip being displayed in the desktop client and in the web client no attachment could be seen anymore. The final code is something like this
LinkedResource embeddedImage = new LinkedResource(imageStream, new System.Net.Mime.ContentType("image/jpeg"));
embeddedImage.ContentId = "ContentId";
altview.LinkedResources.Add(embeddedImage);
mailMessage.AlternateViews.Add(altview);

Add image in email not as linked resource but should be visible in outlook

I want to add image to email. I tried several ways the final solution I am having is to add image as linkedResource but it will increase the size of email and I don't want that as email is already having several attachments.I am using xslt file to get html body of email from XML input. I am adding the image as following
<img src="http://placehold.it/350x150">
but somehow the image is shown as red cross in outlook client in microsoft office and in .mht file.Emails look fine in outlook webmail client and on different browsers.
If I see the network tab in browser after I open the mail in browser from outlook client in microsoft office the request can be seen for url 'http://placehold.it/350x150' but received bytes are zero and response is blank.
Is there any way to add image to email without using linkedResource?
Your help will be really great to me.
Encode the image using base64 and add like this:
<img src="data:image/JPEG;base64,{encoded string}">
Where the {encoded string} part is a base64 encoding of image data. JPEG can be gif or whatever according to type of image.
You could use embedded images.
<img alt="My Image" src="data:image/jpeg;base64,/9j/4S/+RXhpZgAATU0AKgAAAAgACAESAAMAENkDZ5u8/61a+X...more encoding" />
More info here: https://sendgrid.com/blog/embedding-images-emails-facts/
PS. A while ago we have an problem with email rendering in different browsers and email clients. And storing images as described was the best solution (for images, ofc :)).

Alignment of autogenerate mail using c#?

Is there any possible way to align the auto generate mail while upload a file to server. It sends the mail to admin what we upload in server like this
Hi All,
We have uploaded the following files onto FTP site. Details
are as below:
File name File size
D:\New folder\diff2.zip 172
I want to align this one in proper manner anyone help to resolve this..
Well you can save you email template in HTML file and Replace Tag after reading it.. E.g for above create the HTML as you want and then Replace the [[PATH]] Tag before sending email.
see this thread it may be help full for you.
Thanks

Images don't appear in emails

I have a HTML email template in the App_Data folder of my MVC application. In my code, I use this template to send HTML emails to users. This template references a few images in a folder in my project. The issue is that these images don't appear at all when the user receives the email. I have tried to reference the images using ~/path to image/image.gif. I have tried using ../../path to image/image.gif and I have copied the images to the App_Data folder and just referenced the images thus image.gif. Nothing is working. Does anyone have any suggestions?
the images either need to be stored in a publicly accessible location with a full reference to the image <img src="http://my.domain.com/images/filename.ext" /> or the images need to be embedded into the email.
The reason behind the image is not show in email because email client cannot get path you
specified.
For the solution you can do below
First replace the simple image URL to publically access url
[means if you copy the image URL in browser you can access the browser], make sure your image folder is out of authentication
As Jason said you have to put whole url, but if you put your image in App_Data they won't be accessible from outsite because this is a protected folder. You have another option to put images in mail, IMO this is a prefered way to put images in mail, e-mail client won't complain and ask for permission to display images. Here is a example how to do this
http://www.codeproject.com/KB/aspnet/EmbedImage.aspx
you can also use google picasa.
upload the images to picasa, set the visibility to public, get in the album and on the right
side you will have link to this photo link.
press this link and chose the size you want it to be displayed, mark the image only
check box and you will have a link ready to embed in to the mailer.
put the link in the src and that is it.

Embedding Images to Emails

I have created a C# Webform progam for sending reminder emails to clients on my webpage.
It works fine in Outlook. and in Gmail on FireFox.
I just discovered (i dont use IE) that in IE 8 in gmail it doesn't display the image?
It just has an X and alt text.
I cant figure out why IE 8 and gmail wont dispaly the images and i have played with it a bit.
in C#:
LinkedResource emo2 = new LinkedResource(logoPath);
emo2.ContentId = "logo";
emo2.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
htmlView.LinkedResources.Add(emo2);
and in my HTML file :
<img id="header" alt="MyWebpage" src="cid:logo" />
Sending Newsletters via Email is SO frustrating with all the differnent clients. but i never thought Gmail would be my problem!
We had a similar requirement to embed images in to the HTML email instead of link to the images hosted on our website. The main difference being that the user doesn't need to click "show all images" in their email client, i.e. the email should appear immediately rendered to the recipient.
We created the embedded images and it worked great in Outlook and some other email clients, but we discovered that some email clients don't like them as you've noticed with gmail. After a couple of days researching and trying different things, we concluded that there is no silver bullet to make your email correctly show it's embedded images in all major email clients.
We settled and just hosted the images on our website (which means the user gets the "show all images" button...), and used something like:
<img src="http://website/image.jpg"/>
If you have the patience, you could embed images for all email addresses except for certain address (such as #gmail.com), but my preference would be consistency and hence just link to the images.
Try adding this to the end of LinkedResource:
logoPath, MediaTypeNames.Image.Jpeg);
Assuming your logo is a JPG of course!
Also, is htmlView and AlternateView ?
Very late answer but I bet the jpg you are embedding isn't an RBG jpg, its probably CMYK.
I figured out the problem by looking at an existing email with embedded images that was working on IE. Apparently IE is very picky about the content that needs to be shown. Even though I was adding content type
var imgContentType = new ContentType(MediaTypeNames.Image.Jpeg);
It was not showing up in IE. Then I looked at an existing email and the Image in it had the content type "image/png; name="image1.png". Once I added the name to the content type, the images started to show up. I guess IE needs the image extension to know what to do with the image src

Categories

Resources