Solved

Send mails in Chinese characters

Posted on 2001-08-16
2
1,198 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
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…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

823 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