svenkapudija
svenkapudija

Reputation: 5166

Formatting e-mail body (HTML?)

One simple question, what are the ways to format some email body? Especially I would need something like

<table><tr><td></td></tr></table>

tags. But as for now, I couldn't find a way to achieve this (besides bold,italic...)).

Are there any alternatives besides HTML? For final result I would just need some simple table.

EDIT: @EJB @jondavidjohn

This is for Android :)

@EJB

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table>
<tr>
<td>Something</td>
<td>Something</td>
</tr>
<tr>
<td>Something</td>
<td>Something</td>
</tr>
</table>
</body>
</html>

Upvotes: 1

Views: 2607

Answers (5)

David Gidony
David Gidony

Reputation: 1283

I've built this method to format my e-mail massage body. uses Hebrew in HTML for RTL aligning

    private String formatMassageBody(MassageData newMassage) {
    String tmpMassage;

        tmpMassage = "<html><meta charset=\"UTF-8\"><p><body dir=\"rtl\">";
        tmpMassage += "<b>מק\"ט:  </b>" + newMassage.getID() + "<br><br>";
        tmpMassage += "<b>התקבל ב:  </b>" + new Date().toString() + "<br>";
        tmpMassage += "<b>שם הפרוייקט: </b>" + newMassage.getProjectName() + "<br>";
        tmpMassage += "<b>שם מזמין העבודה:</b>" + newMassage.getOrderedBy()"<br>";
        tmpMassage += "<b>טלפון:  </b>" + newMassage.getPhoneNumber() + "<br>";
        tmpMassage += "<b>דחיפות:  </b>";
        tmpMassage += (newMassage.getPriority() == 1) ? "דחוף<br>" : "רגיל<br>";
        tmpMassage += "<b>מילות קוד:  </b>" + newMassage.getTagNames() + "<br>";
        tmpMassage += "</body></p><p><body dir=\"rtl\">";
        tmpMassage += "<br>";
        tmpMassage += "<b>פירוט הטכנאים: </b>" + newMassage.getText() + "<br><br>";
        tmpMassage += "<b>הטכנאי השולח: </b>" + newMassage.getTech() + "<br><br>";;
        tmpMassage += "<b>זמן עבודה משוער: </b>" + newMassage.getTTL() + "<br>";;
        tmpMassage += "</body></p><p></p></meta></html>";

        return tmpMassage;
}

Works like a charm :)

as you can see the common tags i use here are:

    <br> - for a line break.
    <b> Text I want to BOLD </b> - for BOLD text.
    <p>....</p> - new paragraph.
    <meta charset=\"UTF-8\"> - declaring Hebrew characters
    <body dir=\"rtl\">" - setting the text direction to RIGHT-TO-LEFT for Hebrew.

Good Luck

Dave.

Upvotes: 1

E.J. Brennan
E.J. Brennan

Reputation: 46859

My advice would be to look at the source of some of the HTML emails you get...you can definitely format with HTML, including fonts/colors/graphics etc, but most of the rules you use for doing webpages don't apply.

In a lot of ways, its like the "old days", where all the formatting is embedded within the html, instead of pulled in from a css file.

The rules are tricky..if you really want to know how to do it right (for the most number of email clients to be able to see the right formatting - they are not all the same), signup for a free trial account at constant contact or mailchimp, or other big name email provider, create a few emails using their templates, email them to yourself and then study the way they are built and use what you learn to build your own templates.

Alternatively, just study the source of some of the HTML formatted emails that you already get; understand what works is known to work and then adapt to your needs.

Upvotes: 0

RaphMclee
RaphMclee

Reputation: 1623

I tried long before getting it to work but finally:

With the E-Mail app Version 2.3.4 I managed to get it done.

I used the following lines of code.

Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Process Data");
emailIntent.putExtra(Intent.EXTRA_TEXT, text);
context.startActivity(Intent.createChooser(emailIntent, "Chooser Title"));

The text is a simple string with the Html in it.

It does not work with the Gmail application(version 2.3.6)

Upvotes: 0

evereett
evereett

Reputation: 1

I found a work around. It is not a great solution but it works for me. I generate the HTML, and save the text into a .html file. Then, I attach it to the email by passing it through the email intent. Hope this helps!

Upvotes: 0

jondavidjohn
jondavidjohn

Reputation: 62392

yes, HTML emails just simply need to be self sustained documents...

so css needs to be included (no external style sheets)

and all image paths need to be full, not relative.

Upvotes: 0

Related Questions