How to embed an image into an Outlook HTML email message? - winforms

We have a Winforms application which supports dragging and dropping chunks of HTML into Outlook (HTML) mail messages.
Chunks of text are fine.
But how do we proceed with images? Let's assume we don't want to host the images online but instead we want to send them with the email message. Assume also that we do want to see the image inline, not as an attachment (where the recipient's email client supports that, of course).
If you look at the HTML source of an Outlook message there are "cid" tags for images (which point to the image as an attachment I guess), but how do we go about generating a cid/contentid?

If a manual step in the process is an option, you can do it like this:
create the HTML automatically or manually as a saved HTML file, with <img> tags that link to locally-saved image files
attach the HTML to an Outlook email using the 'Insert as text' option tucked away under the down-arrow on the "Insert" button when selecting the HTML file as an attachment.
This populates the HTML email with the HTML from the file and embeds all images. I believe this tool uses Base64 encoding to embed the images as described in Sam's email.
Depending on the workflow, this method might be easier than converting images to Base64 yourself.
Note that this method only works in Outlook for Windows, not Outlook for Mac.

You can embed images in a html email using a base64 encoder. Its quite complicated but you basically encode the image as a text string in the email which is then interpreted.
This does not work in all email clients though.
Take a look at this and see if its what your looking for:
http://www.campaignmonitor.com/blog/post/1761/embedding-images-in-email/
EDIT
The updated campaign monitor post on the clients which work with base64 images.

For the last part of your question, "generating a cid/contentid" I know the only way is useing outlook itself (or Word as a text editor of Outlook) to get that.
I had faced this problem when I needed to insert our company logo beside my signature text on the email.
So, open Microsoft Outlook (office 2016 im ny case) go to File > Options > Mail > Compose Messages > Signatures button
or inside the Outlook New Message windows, go Insert > Picture

If you are using html to make your whole email, you can search google for the same image, and put this in there:
<img src="http://www.google.com/intl/en_ALL/images/logos/images_logo_lg.gif" alt="picture1" />
You can also, use photobucket to host images (if you have to). Basically, you HAVE to have a source for the image.

Related

Want to send a table to outlook using javamail API

I am displaying some data from my database on an html table. Now I want to display a link and on clicking that, I want to open outlook application just like any other mailto link, but I want the table to come as content in my email.
After reading many posts I have come to know that it is not possible to send html content via mailto. So I think I will have to use Javamail API to construct a message. So I have two questions:
1. How do I construct a message via Javamail API with body having a table.
2. How do I open outlook windows App using javamail? All the examples I see on the internet are for sending the email directly.
Why don't you want your message to be html? You can use another rich text format if you think that's better. Otherwise you're stuck with formatting the table as plain text, uses spaces to line up the columns and ASCII characters to draw lines around the columns if you want that.
JavaMail can't open Outlook, but there are other ways to open Outlook from a Java program.

showing inline or embedded images of a mail body in jsp web page

I am polling an exchange server and reading mails from that, saving mail details like To, From , body i.e. either HTML source code or text/plain in database. Body source code I am showing in content editable div in presentation layer and hence mails are being displayed perfectly as in Outlook or Lotus Notes. But I am facing problem with embedded / inline images. As within html source code it is coming as cid:Image01.. hence I am not getting the actual path of images from where I can show that in DIV. Attachments coming as separate attachment but not showing within mail body.
Any idea of doing it? Would be better if any sample java code can be provided. I am not sure about the mechanism, how Outlook or Lotus Notes as a client are able to show those inline images?
Regards
Soumya
You need to process the html content and convert the cid: references into http: references to some URL that your application will use to fetch the corresponding part of the message.

how to extract embedded images in email body using java

I can see many ways to embed images into email but not extracting the embedded image from email body content using java. I'm able to extract the text content in email body but the embedded images is shown with tags and with a CID (component ID). I need to extract it and store as an attachment into DB. I think it should be done like calling the server to extract the content and I'm not sure of it. Please help me to get this done. Your help on this is highly appreciated.
I can see something like this in email headers for an image,
[cid:image002.jpg#01CE978E.097473A0]
Extracting an image is like extracting the content for any other body part. Find the correct MimeBodyPart and use the getInputStream method to read the bytes or use the saveFile method to save the contents to a file.
If that's not working for you, explain in more detail what you've tried and what happened. See also the JavaMail FAQ for debugging tips.

Silverlight and XtraReports - opening generated PDF report in new tab in browser

I'm trying to send a PDF file from a WCF to silverlight client. PDF is generated by DevExpress XtraReports (in method XtraReport CreateReport(string reportTypeName, RootGenericReportParameterContainer reportInformation)).
Acually PDF is saved somewhere on clients computer after choosing save path in file save dialog - DevExpress takes care of everything - but I don't have a clue how to open the PDF in new tab in browser.
And here is another problem. Silverlight 4 has no access to local file system right? So information about local PDF location is useless. Maybe it would be better to save the PDF in WCF and send a link to it to the client - but how?
I would first question why you need to send the file to the Silverlight client. Get rid of that requirement and the solution becomes much simpler. Silverlight can provide a link that opens a new browser tab. That link would be handled by the web domain, processing it as an HttpHandler, generating the PDF file for the browser. Your PDF url doesn't have to reference a physical file, you can still generate it on request, handle querystring values, etc... Lots of different ways to do this.
Seems that the question isn't really about DevExpress or Silverlight - you're just looking to open a [document of some kind] in a new tab. Each browser natively handles things differently, and users can change tab handling to whatever they want. And (as you mentioned) once the user has downloaded the file, you no longer control it.
Your best bet (and the way I do it) is probably to have a link pointing to a handler/file using "target='_blank' " in the anchor tag on the webpage. From the server side, you would want to set the "Content-Disposition" header to "Inline" to indicate to the browser that the document should be displayed in place instead of downloaded ("Attachment").

silverlight in html EMAIL body

I have a news letter which i did in silverlight, is there a way to send it in email. like as you include html tags, is there a way to include silverlight xap package in it.
Probably better to reference a webpage containing your silverlight content.
Technically, you could put the path to the .xap hosted on a website into an HTML email body, but nearly all mail clients will not display this - most even prevent images from loading by default.
Most email systems will prevent you from embedding active content like SilverLight, as it presents a security risk. Your only option probably is to put your SilverLight app on the web, and just email a link to it.
Don't if you want your newsletter to be read by anyone. See this article for a good list of do's and don'ts when sending emails.
Don't listen to those guys, they're probably FlashHeads... ;)
Besides that they give up too easily. More power to ya!
I assume this newsletter is for an audence that specifically desires your content: i.e a club or similar organization that doesn't have a windows based webserver.
What you do is attach the file in such a way that they drag a zip containing the files that would normally be served from a website to the hard drive - right click - extract all then they run it by clicking on an HTML file with .htm extension that hosts the silverlight plugin instead of an aspx file.
One note that probably won't matter to you is that without a server backing this up the content can't really send you back any info but it CAN get dynamic info that comes from say RSS feeds or WCF services hosted on the web.

Resources