linux-il  

Re: HTML email question

Lior Okman
Wed, 28 Nov 2007 06:17:05 -0800

Hetz Ben Hamo wrote:

Hi,

I'm trying to write a very simple shell script which creates a simple
hebrew text file, which is then being sent by email using sendmail.

Here's the script, pretty basic one..

#!/bin/bash
echo "From: [EMAIL PROTECTED]" >> mail.txt
echo "To: [EMAIL PROTECTED]" >> mail.txt
echo "Subject: =?UTF-8 úéøáòá äòãåä=" >> mail.txt
IIRC, your subject should be in base64 encoding, since email headers should be pure ASCII.

For example:
Subject: =?UTF-8?B?16DXmdeh15nXldef?=

breaks down like this:

Subject: =?<Encoding>?B?<base64 encoding of a UTF-8 string with hebrew>?=

echo 'Content-Type: text/html; charset="UTF-8";' >> mail.txt
echo '<html xmlns="http://www.w3.org/1999/xhtml"; dir="rtl"
xml:lang="he" lang="he">' >> mail.txt
echo '<meta http-equiv="Content-Type" content="text/html;
charset=utf-8">' >> mail.txt
echo '<DIV id="main" dir="rtl">' >> mail.txt
echo "?úéøáò ùé" >> mail.txt
echo "!ãáåò äæ ïë íà" >> mail.txt
echo "</DIV>" >> mail.txt
echo "</html>" >> mail.txt
Since SMTP is by default supposed to be 7bit ASCII, you should either mime-encode your actual message body, or use the following header to try to pass 8bit encoding:

Content-Transfer-Encoding: 8bit

And for HTML only mail, you should also consider these headers:

MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8

(the file has been edited by gvim in windows).

The mail.txt comes out OK, but when I'm sending it to my gmail
account, the incoming mail comes gybrish both in subject and the text.

I admit, I have 0 experience creating HTML mails, is there any good
link to learn how to make it "correctly" so users can see both subject
and the html in good way?

Thanks,
Hetz




================================================================To unsubscribe, 
send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]