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
Related
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);
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" >
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 :)).
I have create html with image(base 64 string ) for sending mail.
But on Outlook it doesnt show image and not support html.
what to do, Please help me.
thanks
Kamlesh
This may be the answer you're looking for - How to create an email with embedded images that is compatible with the most mail clients
Note that images are embedded using <img src="cid:....">
I have this issue where i cant download the attachment images in a forward message.
Content id for this images are like: cid:companylogo.jpg#1231.1231.
What my application does is read emails, donwload images upload them to picture library in sharepoint and then change the src value of this images from the original html for the new urls which are the ones of the sharepoint picture library.
I got this working pefectly, but yesterday we were trying with forward messages, and the application couldn't handle this type of attachments.
For starters when opening outlook the email appears as it has no attachments, we did some research that it does not has attachments but makes reference to the original email which was then forward.
I have no clue on how to get this image from the forward image.
If anyone has any ideas or resources there are much welcome.
Sorry for bad english not my native language