Thursday, March 09, 2006

How do I use UTL_SMTP send mail charset thai (TIS-620)

- - Set Message format--
/*
utl_smtp.data(c,'MIME-Version: 1.0' CHR(13) CHR(10)'Content-Type: text/html; charset=utf-8' CHR(13)CHR(10) 'Content-Transfer-Encoding: 8bit' CHR(13)CHR(10) msg);
*/


--Change to --

utl_smtp.open_data(c);
utl_smtp.write_raw_data(c, utl_raw.cast_to_raw('MIME-Version: 1.0' CHR(13) CHR(10)'Content-Type: text/html; charset=tis-620' CHR(13)CHR(10) 'Content-Transfer-Encoding: 8bit' CHR(13)CHR(10) msg));
utl_smtp.close_data(c);

utl_smtp.quit(c);

********************************************
Example use UTL_SMTP (char-set: TIS-620 thai) (subject + body = thai)

-----------------------------------------------------
CREATE OR REPLACE PROCEDURE test_mail
AS

connection UTL_SMTP.connection;
v_reply UTL_SMTP.reply;
sender VARCHAR2 (50);
recipient VARCHAR2 (50);
subj VARCHAR2 (100);
BODY VARCHAR2 (1000);
begin
sender := 'sen_mail@host';
recipient := 'rep_mail@host';

-- Subject mail--
subj := 'ดี'; -- Thai language---
-- Body mail--
BODY := 'สวัสดีครับ'; --Thai language--

connection := UTL_SMTP.open_connection ('mail.server.com', 25);
v_reply := UTL_SMTP.helo (connection, 'host.co.th');
v_reply := UTL_SMTP.mail (connection, sender);
v_reply := UTL_SMTP.rcpt (connection, recipient);

utl_smtp.open_data(connection);
UTL_SMTP.WRITE_DATA(connection, 'From: ' ||sender|| UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(connection, 'To: ' ||recipient ||UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(connection, 'MIME-Version: 1.0'|| UTL_TCP.CRLF);
UTL_SMTP.WRITE_DATA(connection, 'Content-Type: text/html;charset=tis-620'||UTL_TCP.CRLF);
UTL_SMTP.write_raw_data(connection,utl_raw.cast_to_raw('Subject:' ||subj));
UTL_SMTP.WRITE_DATA(connection, UTL_TCP.CRLF ||'' ||UTL_TCP.CRLF);
UTL_SMTP.write_raw_data(connection, utl_raw.cast_to_raw(BODY));
utl_smtp.close_data(connection);
UTL_SMTP.quit (connection);

end;
--------------------------------------------------------

Enjoy!

No comments: