How to embed an image in email? - java

I am trying to write a Java program where I need to send an image to Gmail. I am sending the image as an embedded object.
<img src="data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAACcAAAAsCAYAAADmZKH2AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABISURBVFhH7c4hAQAgEAAxEhGGZN8YOkwhTsxvnT33V+VUOVVOlVPlVDlVTpVT5VQ5VU6VU+VUOVVOlVPlVDlVTpVT5dTHubkPuMrNUFKjQWUAAAAASUVORK5CYII=">
Other mail service providers are showing it fine, but Gmail specifically is removing it, so it is not visible in the message.
How can I make it visible in Gmail as well as the other mail service providers?

Place the image in a publicly accessible server and give the url for src attribute instead of dataUrl.

It is not possible in Gmail, outlook etc. They ignore base64 images.
For further information follow the link at below.
https://www.campaignmonitor.com/blog/email-marketing/2013/02/embedded-images-in-html-email/
There is an alternative way for doing this. Embed images in the email using the cid method. (Basically including the image as an attachment, and then embedding it).
https://www.campaignmonitor.com/blog/how-to/2008/08/embedding-images-revisited/

Related

HTML table loses border when mail is forwarded

I am trying to include HTML tables with Outlook emails. It is able to render and provide the content when the mail is sent initially. But, the table loses it's border whenever the mail is forwarded. But, the structure is preserved.
Is there anyway to embed some css so that the content is rendered whenever the mail is forwarded ?
EDIT : I am using outlook to send the mails and the tables are already inline styled. Also the code is written for generation of email using apache velocity engine.
it's wired as each email client treats forwarded messages, so if gmail adds some classes to restyle the forwarded tables I don't think there's much you can do about that. I would suggest trying to use some divs inside table cells and give a border to those.
and there's a tool that will help you so much when writing email templates, called emogrefier. basically you write css and it automatically applies that style as inline. you can even use scss and set the exported file to be included as inline style.

Secure way to store client information and send back to client - java spring mvc

I am developing web service for a mobile application.As a part of this, I need to create some confidential reports and store it in the server and send it back to client on request as links (from which the file can be downloaded) . The requirement is , they should be able to open and view the documents in mobile.
If I have to send the file links, I should be having it in a web application which provides a public url . But does that make the reports secure ?
Can I send it as multipart file instead of url? In that case the problem is hybrid (phonegap ) platform cannot directly access the files. Is there any way to do it on phonegap?
If I use any encryption technique , may be like encrypting the url , the actual url can still be seen from the browser which opens inline .
Can anyone suggest a effective way to do send confidential documents to mobile ?
You can try creating and storing the report structure in PDF format on the server. Most browsers on mobile open up pdf files directly within the browser.
Since these are PDF files, you can password protect these and only clients who know the password can view the files.
Alternatively you can have a login filter, so that whenever a client hits your web service, he first enters some valid credentials to gain access to the document.
Encrypting the URL gives no benefit as the resource you intend to secure is the information in the document served back to the client.

Best way to send an E-Mail from a java Application

I've been searching for the best way to send an e-mail with an attachment by my java application. I want to use this as an users bug report with logger files. The recipient should be my own e-mail address. I'd prefer the use of an e-mail client.
I tried the following:
Send an e-mail with user authentification like this. I don't want to use this, because the user would need to reveal his e-mail account and password. Furthermore, I'd have to set the properties for every e-mail adress, which is impossible.
Send an e-mail directly to my own e-mail address like this in Listing 16.16 (didnt found an english example). The problem is every e-mail server is using POP authentification nowadays, that means the recipient e-mail server won't accept my e-mail.
Using the mailto URL syntax like this. Doesn't work aswell, because the attachment function isn't working properly in every e-mail client. Best solution so far is to brief the user to add the attachment by himself, after I would put it to his desktop. Or upload the data and add a link to the e-mail body.
The last way I've found is this one. As you could assume this won't work either, because the localhost needs to be connected to the internet and capable enough to send an e-mail.
Hopefully I explained my problem well enough. Is there a different way to send bug reports?
The generally accepted way to get around the problems you describe is to keep all the email logic server side, and then have your application call a web service with the appropriate parameters. It's pretty easy to knock a PHP script / servlet up that will do the job and then send the results on via email, put them in a mysql database or so on.
However, if you can't / don't want to / won't keep this server side, I'd recommend using JavaMail to create a MimeMessage, then using writeTo() to write this to an EML file.
You can then do the usual:
Desktop.getDesktop().open(emlFile);
...which will open the EML file with the default application for handing those files, which is almost always the mail client. Still not foolproof, but if you're determined on sending the email from the client directly I think that's as good as you'll get.

Auto Generated Mail

Perhaps this kind of question comes under not to ask category but for the sake of application I have to ask.So pardon me.
At the time of Log in,I found that(suppose)If I am unable to remember my password,then I have to put my email-id then an auto generated reply come from that's hosted site with
a new link for generating another new password or
simply sending password(that means password isn't encrypted,I guess) in reply.
watching the source code it's hard to predict,but I want to know(if they are using jsp) then which protocol is used for this auto generated mail what are the other things to remember to achive this, while I'm also making an application for auto generated mail.
I have done this using javax.mail api in java
google for sending mail using java...
define content of mail in template or resource file and send mail whenever user clicks on forgot password link.
It is using SMTP protocol only.

sending file as a link instead of an attachment in the mail

Is it possible to send the file as a link instead of attaching the file in the email. I am sending an email using Java . Now, i have a requirement thatI don't want to send the file as an attachement instead I need to send it as a link.
Link will something be like abc.com\report\excel\"fileName", in which abc.com is the host/ machine name, and rest is the path location.
Thanks.
Mail format does't allow meta-attachments (i.e. by reference, not by instance).
Your only option is sending HTML email with HTML link to the file (and of course it should be accessible via internet).

Categories