Solved

Send mails in Chinese characters

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

Title # Comments Views Activity
PL/SQL Two PAYER_IDs with PAYER_TYPES these two types 4 35
Calculating percentages per course - Oracle Query 3 41
T-SQL Convert to PL/SQL 23 77
report returning null 21 79
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…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

919 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

14 Experts available now in Live!

Get 1:1 Help Now