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.
Related
I want to develop a blog application with Django backend and React frontend. I shall be using Postgresql.
I want to use a rich text editor like Quill to write the blog article. My questions:
I heard that article written in a text editor needs to be converted to HTML before saving in the database. If so, how do I do this in Django Rest Framework?
How do I present the article keeping the same style and formatting in the frontend from the database?
Say, I include multiple photos in the article. How do I save all the photos in the database? i.e. what should be the schema then?
I want to have my doubts clear before I jump in.
I'm also doing the same thing at the moment. For your answers :
In DRF, the simplest way to post the data is by using Textfield in your model. Rich text field (with Tags) will be stored in the Postgres. In the Admin page or the DRF API you'll see something like this
Then, to re-render it to the front end, you can use any HTML Parser library. for example I'm using "react-html-parser" that simply convert the rich text into the defined styling.
As for Image, this is a bit tricky, and I havent done this part myself but what i could think of right now is you would create another model & end points to store the images.
when sending the post request to the django, you would convert the base file path/url from the front end to back end. example :
original > http://localhost:3000/image/efewf23r.jpg
new (django) > http://localhost:8000/media/img/img_model/efewf23r.jpg
then do a second post request to the image itself and make sure django would rename the the file as per what we set above.
Let me know if you found a better solution.
It's been long since I posted this question. After that, I have gained enough working knowledge to make Quill.js (the rich text editor I'm using) work with React.JS, or, in my case Next.JS. So, this is focused on Quill.js only. The Quill npm package more specific to ReactJS is react-quill. I am presenting it as beginner friendly as possible.
A built-in function is provided with Quill: editor.getHTML(). editor is the current editor instance, where one types the content. This method generates the innerHtml of the content one prepares in the editor.
To save it to the databse, simply POST it to your back-end. But you must sanitize this innerHtml before passing it to the database. Can't say about server-side but I had to do this sanitization on the client-side. One good package is DOMPurify. You need to save this to the database if you want to present it in the same manner as it was typed in the browser.
The first point also provides the solution to my 2nd question. But one important point: The content one writes in Quill editor is also available as a JSON like format called quill-delta. You can get the delta with the function editor.getContents(). You need to POST it to the database if you want to edit the content in a later time.
To edit, you need to get this delta from the database and then initialize Quill editor with this delta in the value attribute.
For example, the text in orange is the delta representation of the text in the editor:
codepen source.
There is another function editor.getText() which extracts all the text from the editor.
Photos. Generally in Quill, you simply put the photo in the editor and Quill generates a base64 encoded delta for the photo. It's this easy. You don't need to worry about separate image fields.
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.
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.
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").
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.