Send mail - UTF-8 problems [message #537659] |
Fri, 30 December 2011 02:08  |
 |
wtfn00b
Messages: 115 Registered: October 2011 Location: Latvia
|
Senior Member |
|
|
[MERGED by LF]
Good day, I'm trying to send e-mail using UTL_SMTP with UTF-8 coding. I have a problem that the UTF-8 letters become `?`.
So here is the code:
p_to varchar2(250);
p_from varchar2(250):='email_address';
p_subject varchar2(250):='...vienotā...';
P_smtp_hostname varchar2(255) := 'IP';
P_smtp_portnum varchar2(5) := '25';
p_text varchar2(32767);
p_html varchar2(32767);
l_boundary varchar2(255) default 'a1b2c3d4e3f2g1';
l_connection utl_smtp.connection;
l_body_html clob := empty_clob;
l_offset number;
l_ammount number;
l_temp varchar2(32767);
l_connection := utl_smtp.open_connection(p_smtp_hostname, p_smtp_portnum);
utl_smtp.helo(l_connection, p_smtp_hostname);
utl_smtp.mail(l_connection, p_from);
utl_smtp.rcpt(l_connection, p_to);
l_temp := l_temp || 'MIME-Version: 1.0' || chr(13) || chr(10);
l_temp := l_temp || 'To: ' || p_to || chr(13) || chr(10);
l_temp := l_temp || 'From: ' || p_from || chr(13) || chr(10);
l_temp := l_temp || 'Subject: ' || p_subject || chr(13) || chr(10);
l_temp := l_temp || 'Reply-To: ' || p_from || chr(13) || chr(10);
l_temp := l_temp || 'Content-Type: multipart/alternative; boundary=' || chr(34) ||
l_boundary || chr(34) || chr(13) || chr(10);
dbms_lob.createtemporary(l_body_html, false, 10);
dbms_lob.write(l_body_html,length(l_temp),1,l_temp);
l_offset := dbms_lob.getlength(l_body_html) + 1;
l_temp := '--' || l_boundary || chr(13)||chr(10);
l_temp := l_temp || 'content-type: text/html; charset=utf-8' || chr(13) || chr(10) || chr(13) || chr(10);
dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
l_offset := dbms_lob.getlength(l_body_html) + 1;
dbms_lob.write(l_body_html,length(p_text),l_offset,p_text);
l_temp := chr(13)||chr(10)||chr(13)||chr(10)||'--' || l_boundary || chr(13) || chr(10);
l_temp := l_temp || 'content-type: text/html; charset=utf-8' || chr(13) || chr(10) || chr(13) || chr(10);
l_offset := dbms_lob.getlength(l_body_html) + 1;
dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
l_temp := chr(13) || chr(10) || '--' || l_boundary || '--' || chr(13);
l_offset := dbms_lob.getlength(l_body_html) + 1;
dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
l_offset := 1;
l_ammount := 1900;
utl_smtp.open_data(l_connection);
while l_offset < dbms_lob.getlength(l_body_html) loop
utl_smtp.write_data(l_connection, dbms_lob.substr(l_body_html,l_ammount,l_offset));
l_offset := l_offset + l_ammount ;
l_ammount := least(1900,dbms_lob.getlength(l_body_html) - l_ammount);
end loop;
utl_smtp.close_data(l_connection);
utl_smtp.quit(l_connection);
dbms_lob.freetemporary(l_body_html);
The code is taken an example from internet source.
Everything works fine but the UTF-8 not 
Can someone tell me whats wrong ?
Best regards,
wtfn00b.
[Updated on: Mon, 02 January 2012 03:53] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UTL_MAIL to work with UTF-8 [message #537861 is a reply to message #537659] |
Mon, 02 January 2012 03:12   |
 |
wtfn00b
Messages: 115 Registered: October 2011 Location: Latvia
|
Senior Member |
|
|
Good day, I have problem with UTF-8.
I use function like this:
utl_mail.send(sender => p_from, recipients => p_to, subject => p_subject, message => p_text,
mime_type => 'text; charset=utf-8');
But only Subject is shown in UTF-8.
The text inside message is with `�`.
Can someone tell me what can I do to fix it ?
Best regards,
wtfn00b.
[Updated on: Mon, 02 January 2012 04:05] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|