Solved

Send mails in Chinese characters

Posted on 2001-08-16
2
1,220 Views
Last Modified: 2007-12-19

Hi all

I'm using UTL_SMTP package to send mails in a stored procedure.
My database character set is set to traditional Chinese
(ZHT16BIG5).
All Chinese characters received by the mail clients are converted to "?".

I think this may happen in all multi-byte characters.
Is there ever a way in PL/SQL to solve this problem ?

Thanks in advance.

0
Comment
Question by:AlbertYou
2 Comments
 
LVL 9

Accepted Solution

by:
dbalaski earned 100 total points
ID: 6395584


Hi,

From what I understand,  you are going to need to use the MIME format.  

As from this clip:
According to the Oracle documentation, the original SMTP protocol communicates using 7-bit
 ASCII. Using UTL_SMTP, all text data (in other words, those in VARCHAR2) will be converted to
 US7ASCII before it is sent over the wire to the server. When the target SMTP server supports
 8BITMIME extension, users of multi-byte databases may convert their non-US7ASCII, multi-byte
 VARCHAR2 data to RAW and use the write_raw_data() API to send multi-byte data using 8-bit
 MIME encoding.


How to send MIME format:
Put the following lines  right after the message subject that you send to utl_smtp.data.

 'MIME-Version: 1.0' || crlf ||
 'Content-type: text/plain; charset=iso-8859-1' || crlf ||
 'Content-transfer-encoding: 7bit' || crlf ||
 '' || crlf ||

(use the appropriate characterset in place of  "charset=iso-8859-1")

I think this might work -- give it a try...

dB
0
 
LVL 2

Author Comment

by:AlbertYou
ID: 6395784

Hi Laski

I have tried your way, it did not work.
I don't know what does
 "right after the message subject" mean.

However, your answer gives me a good hint that
this problem is derived from MIME format.

I have solved this problem by using the UTL_RAW package.
The following is my code.


DECLARE
   c utl_smtp.connection;
   PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
   BEGIN
      utl_smtp.write_raw_data(c, utl_raw.cast_to_raw(name || ': ' || header || utl_tcp.CRLF));
   END;
   PROCEDURE put_line ( p_line_text in varchar2) is
   begin
      utl_smtp.write_raw_data(c, utl_raw.cast_to_raw(p_line_text || utl_tcp.CRLF));
   end;
BEGIN
   c := utl_smtp.open_connection('smtp-server.acme.com');
   utl_smtp.helo(c, 'foo.com');
   utl_smtp.mail(c, 'sender@foo.com');
   utl_smtp.rcpt(c, 'recipient@foo.com');
   utl_smtp.open_data(c);
   send_header('From',    '"Sender" <sender@foo.com>'');
   send_header('To',      '"Recipient" <recipient@foo.com>');
   send_header('Subject', 'Chinese subject' );
   put_line(''); -- Do not remove this line, otherwise the mail content will be empty !!!
   put_line('Chinese messages');
   utl_smtp.close_data(c);
   utl_smtp.quit(c);
EXCEPTION
  WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
       utl_smtp.quit(c);
       raise_application_error(-20000,
         'Failed to send mail due to the following error: ' || sqlerrm);
END;


Thanks anyway.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question