Solved

Send mails in Chinese characters

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

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Salary Amount Format 13 56
Pfile and SPfile - Oracle 2 35
Oracle DATE Column Space 11 44
Oracle and DateTime math 6 13
Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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 information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

705 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now