How to send html content with image through android default email client? - android

How can we get inline images in default email client for android through Hypertext Markup Language (HTML) ?

You can not. As default Email application's doesn't support <img /> tag.
Because, ImageSpan doesn't implementing Parcelable.
Hence its failed with Intent's PUT_EXTRA.
Its works only for basic tags, like, <b>, <i> ..etc
Look at Sending html email in android using <table>, etc. - is there really no relatively built-in Intent way? and How to show an image in the email body?

String body ="<html><body><table>...</table></body></html>";
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body).toString());
startActivity(Intent.createChooser(emailIntent, "Email:"));
Unfortunately, the <table> ,'img' tag isn't supported. Supported tags are actually more dependent on the email client you use to send the email - some of them are more finicky/restrictive than others. Most of them use the super-basic formatting tags like <b>, <i>, <h1>, and so on, though.

Related

CSS not working while Sending HTML email via Intent in android

I want to send Html via mail app, problem is with CSS is not working when I am using Gmail to compose/send mail
And here is the intent spinet
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, "Summary");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<div style='background: red;'>TEST</div>"));
intent.putExtra(Intent.EXTRA_HTML_TEXT, "<div style='background: red;'>TEST</div>");
intent.setType("text/html");
startActivity(Intent.createChooser(intent, "Send mail"));
Even I applied inline CSS its not working, Can Any help what's wrong am I doing
Gmail cuts off the head, so the CSS gets lost. For HTML Emails, you should always use inline styles.
Edit:
The general rule to use inline styles is still true, but in your specific case, it seems to be an issue with sending a HTML Mail with an Intent. I found in another answer on SO, that this may isn't possible.

Android: Send HTML text using ACTION_SEND Intent

I'm trying to send some HTML formatted text via the ACION_SEND Intent in my app. The HTML file is located in my assets directory and it has links to some images and contains other CSS stylings. Thus far I've tried the following:
private Intent getEmailIntent(String deepLink) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
// sharingIntent.setType("text/html");
sharingIntent.setType("text/plain");
// sharingIntent.setType("message/rfc822");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getShareSubject());
sharingIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(getHtmlTextFromAssetsFile("myHtml.html")));
return sharingIntent;
}
As you can see from the above method, I've tried using all three of the IntentTypes in the code, without success.
The HTML file has CSS within a <style> tag , and that is not applied. It just shows up as plain text in all cases. No images (remotely located) are loaded. And </br> tags are ignored.
Has anyone worked with this? How can I get my app to send such an email? Any pointers would be helpful.
Probably not many email clients on Android support HTML. What you can do is providing plain text in EXTRA_TEXT and putting the HTML in EXTRA_HTML_TEXT as documented here: https://developer.android.com/reference/android/content/Intent.html#ACTION_SEND

Embed html table tag in email intent android

I am working on a concept in which I have to embed html table tag in email body.I tried some work around code it's working fine in 2.2 and 2.3 OS versions but the same code is not working in latest OS versions like 4.0 etc.
I also tried Spannable and Html.fromHtml()but it's also not working.
Here is my code which is working on 2.2 and 2.3 OS versions:
//SEND EMAIL
private void sendEmail(String imageUri) throws WriterException{
//....................Prepare share email data.............................
int itemNumber=0;
titleBuffer=new StringBuffer();
titleBuffer.append("<html><body><table border="+"1"+"><tr border="+"0"+"><th>Item number</th>"+
"<th>Barcode</th>"+"<th>Product name</th>"+"<th>Quantity</th></tr>");
for(int i=0;i<_productList.size();i++){
itemNumber=i+1;
titleBuffer.append("<tr border="+"0"+"><td>"+itemNumber+"</td>"+
"<td>"+_productList.get(i).getProductBarcode()+"</td>"+"<td>"+_productList.get(i).getProductName()+"</td>"+
"<td>"+_productList.get(i).getProductQuantity()+"</td></tr>");
/*titleBuffer.append("<tr border="+"0"+"><td>"+itemNumber+"</td>"+
"<td>"+_productList.get(i).getProductBarcode()+"</td>"+"<td>"+_productList.get(i).getProductName()+"</td>"+
"<td>"+_productList.get(i).getProductQuantity()+"</td>"+"<td>"+
"<img src="+"/'data:image/png;base64, "+generateBarcodeImage(GenerateBarcode.encodeAsBitmap(_productList.get(i).getProductBarcode(),
BarcodeFormat.CODE_128, 600, 300))+"/'/></td></tr>");*/
}
titleBuffer.append("</table></body></html>");
SpannedString bar = new SpannedString(titleBuffer.toString());
if(_productList.size()==0){
titleBuffer.append("NA");
}
//..........................................................................
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,"");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Shopping List");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,titleBuffer.toString());
emailIntent.putExtra(Intent.EXTRA_STREAM, emailImageUri);
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
Also find the attached image which proves it worked in 2.2 and 2.3 OS versions.
It depends on the email client which is handling it. Not all the email clients supports all the HTML tags.Atleast Gmail doesn't support it. Its works only for basic tags, like, <b>, <i> etc.It doesn't work for especially <img> tag.
See these so posts for more info,
Sending html email in android using <table>, etc. - is there really no relatively built-in Intent way?
Android, How to send HTML email and force Android to send it through G-Mail not other applications?
How to send html content with image through android default email client?
try below code :-
final Intent shareIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject");
shareIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append("<p><b>Some Content</b></p>")
.append("<small><p>More content</p></small>")
.toString())
);
for more info see below link:-
android - How to format the text as table in email body of email client
How to send HTML email
http://blog.iangclifton.com/2010/05/17/sending-html-email-with-android-intent/

Is it possible to send html with the mail intent?

is it possible to send html with the mail intent. I've seen some questions about this, but they are al answered with something like this:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, titleString);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(htmlString));
startActivity(Intent.createChooser(emailIntent, "Email:"));
I'm trying to send some data in a table but the Html.fromHtml will remove my table layout..
Is there any other option to send a html content type email...?
create email body with tags, that are supported by android.text.Html. https://github.com/android/platform_frameworks_base/blob/master/core/java/android/text/Html.java
Solved it by the following work-around:
Create a html file and send it as a attachment..

How to send HTML email

i found a way to send plain text email using intent:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new
String[]{"example#mail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Test");
But I need to send HTML formatted text.
Trying to setType("text/html") doesn't work.
You can pass Spanned text in your extra. To ensure that the intent resolves only to activities that handle email (e.g. Gmail and Email apps), you can use ACTION_SENDTO with a Uri beginning with the mailto scheme. This will also work if you don't know the recipient beforehand:
final Intent shareIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject");
shareIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append("<p><b>Some Content</b></p>")
.append("<small><p>More content</p></small>")
.toString())
);
Been trying to send html via gmail app for a while, so decided to leave some insight on what I found, just in case someone else is having similar issues.
Seems like no matter what I did, I couldn't get the html to have bold text in it.
Then I've tried switching to outlook client and to my surprise it was working just fine.
Html markup was also working on other older devices, but not on mine (galaxy s7 API 26), so I figured, that gmail app seems to have dropped support for html syntax that comes from intent or maybe now you're required to provide it in some very specific way which is not clearly documented.
Last gmail version that worked for me was version 6.9.25... on Nexus 5X API 25 emulator (Nougat)
And it stopped working starting version 7.5.21... On Nexus 5x API 26 emulator (Oreo)
This was very helpful to me for the HTML, but the ACTION_SENDTO didn't quite work for me as is - I got an "action not supported" message. I found a variant here which does:
http://www.coderanch.com/t/520651/Android/Mobile/no-application-perform-action-when
And here's my code which combines the two together:
String mailId="yourmail#gmail.com";
Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto",mailId, null));
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject text here");
// you can use simple text like this
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Body text here");
// or get fancy with HTML like this
emailIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append("<p><b>Some Content</b></p>")
.append("<a>http://www.google.com</a>")
.append("<small><p>More content</p></small>")
.toString())
);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
I haven't (yet) started Android development, but the documentation for the intent says that if you use EXTRA_TEXT, the MIME type should be text/plain. Seems like if you want to see HTML, you'd have to use EXTRA_STREAM instead...
You must to change "EXTRA_TEXT" for "EXTRA_HTML_TEXT"
https://developer.android.com/reference/android/content/Intent.html#EXTRA_HTML_TEXT
What about just trying to add some html in the text area?
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "<strong>Test</strong>");

Categories

Resources