Home » SQL & PL/SQL » SQL & PL/SQL » Send mail - UTF-8 problems (11.2.0.1.0 - Production, jdeveloper 11g R2 11.1.2.1.0, Win7 Prof. 64-bit, Weblogic server)
Send mail - UTF-8 problems [message #537659] Fri, 30 December 2011 02:08 Go to next message
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 Sad
Can someone tell me whats wrong ?

Best regards,
wtfn00b.

[Updated on: Mon, 02 January 2012 03:53] by Moderator

Report message to a moderator

Re: Send mail using utl_smtp no UTF-8 [message #537661 is a reply to message #537659] Fri, 30 December 2011 02:17 Go to previous messageGo to next message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Do not use UTL_SMTP, use UTL_MAIL.

Regards
Michel
Re: Send mail using utl_smtp no UTF-8 [message #537671 is a reply to message #537661] Fri, 30 December 2011 02:56 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
Can you please explane me why ?

Can I rename `utl_smtp` to `utl_mail` ?
And will it work ?


Best regards,
wtfn00b.

[Updated on: Fri, 30 December 2011 03:33]

Report message to a moderator

Re: Send mail using utl_smtp no UTF-8 [message #537677 is a reply to message #537671] Fri, 30 December 2011 03:32 Go to previous messageGo to next message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Because it is better.
UTL_SMTP was used when UTL_MAIL did not exist.

Regards
Michel

[Updated on: Fri, 30 December 2011 03:33]

Report message to a moderator

Re: Send mail using utl_smtp no UTF-8 [message #537678 is a reply to message #537677] Fri, 30 December 2011 03:33 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
Can I rename `utl_smtp` to `utl_mail` ?
And will it work ?

Best regards,
wtfn00b.
Re: Send mail using utl_smtp no UTF-8 [message #537682 is a reply to message #537678] Fri, 30 December 2011 03:42 Go to previous messageGo to next message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
No, it is not just a rename thing, UTL_MAIL embeds all what is necessary to send mail.

In addition, to see UTF-8 mail your mail tool should be able to read them.
The first thing to do should be to test that.

Regards
Michel
Re: Send mail using utl_smtp no UTF-8 [message #537693 is a reply to message #537682] Fri, 30 December 2011 04:47 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
I have error:
Error(516,13): PLS-00201: identifier 'UTL_MAIL.SEND' must be declared


Try to use like this:
BEGIN
................
  UTL_MAIL.send(sender => p_from,
                recipients => p_to,
                subject => p_subject,
                message => p_text,
                mime_type => 'text; charset=utf-8');
................
END;


Best regards,
wtfn00b.
Re: Send mail using utl_smtp no UTF-8 [message #537695 is a reply to message #537693] Fri, 30 December 2011 05:07 Go to previous messageGo to next message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
UTL_MAIL is not installed by default, ask your DBA to do it.
In addition, even if it is installed access to it is not granted to everyone.

Regards
Michel

[Updated on: Fri, 30 December 2011 05:07]

Report message to a moderator

Re: Send mail using utl_smtp no UTF-8 [message #537698 is a reply to message #537695] Fri, 30 December 2011 05:11 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
How can I install it ?
Is it possible to do with PL/SQL command or no ?

Best regards,
wtfn00b.
Re: Send mail using utl_smtp no UTF-8 [message #537699 is a reply to message #537698] Fri, 30 December 2011 05:13 Go to previous messageGo to next message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Using utlmail.sql and prvtmail.plb scripts.

Regards
Michel
Re: Send mail using utl_smtp no UTF-8 [message #537700 is a reply to message #537699] Fri, 30 December 2011 05:14 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
Where can I get theim ?

Best regards,
wtfn00b.
Re: Send mail using utl_smtp no UTF-8 [message #537710 is a reply to message #537700] Fri, 30 December 2011 06:13 Go to previous messageGo to next message
Littlefoot
Messages: 21826
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Do you know how to search for files on your disk using your operating system's search capabilities? ("Your" might turn into "database server", but the rest is still valid).
Re: Send mail using utl_smtp no UTF-8 [message #537711 is a reply to message #537710] Fri, 30 December 2011 06:47 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
Oh, okey, than I will contact my DBA and tell him to do this:
Using utlmail.sql and prvtmail.plb scripts.
Like Michel told.

Best regards,
wtfn00b.
UTL_MAIL to work with UTF-8 [message #537861 is a reply to message #537659] Mon, 02 January 2012 03:12 Go to previous messageGo to next message
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

Re: UTL_MAIL to work with UTF-8 [message #537866 is a reply to message #537861] Mon, 02 January 2012 04:28 Go to previous messageGo to next message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Is your text really written in UTF-8?

Quote:
But only Subject is shown in UTF-8.

How do you know that?

Regards
Michel
Re: UTL_MAIL to work with UTF-8 [message #537878 is a reply to message #537866] Mon, 02 January 2012 05:47 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
I send mail and I see that subject shows UTF-8 but body text only the `?`.
I'm requiting e-mails with outlook.

Regards,
wtfn00b.
Re: UTL_MAIL to work with UTF-8 [message #537880 is a reply to message #537878] Mon, 02 January 2012 05:54 Go to previous messageGo to next message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
I send mail and I see that subject shows UTF-8

What does "show" mean? How do you verify it is UTF-8 character?

Quote:
I'm requiting e-mails with outlook.

So verify in the source of the message if it is in UTF-8 or not.
Verify your Outlook is configured to understand UTF-8.

Regards
Michel
Re: UTL_MAIL to work with UTF-8 [message #537881 is a reply to message #537880] Mon, 02 January 2012 05:57 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
This is how it's looks like: http://uploadpic.org/storage/2011/epNbb4I7L45LCA1ohYzxEYsz.png

I will check outlook settings but I think there is everything okey with it.
Because I get e-mails in UTF-8 all day long.

Best regards,
wtfn00b.
Re: UTL_MAIL to work with UTF-8 [message #537882 is a reply to message #537881] Mon, 02 January 2012 06:00 Go to previous messageGo to next message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Nothing proves the subject is in UTF-8.
What you posted proves you can read it with your default language.

Regards
Michel
Re: UTL_MAIL to work with UTF-8 [message #537883 is a reply to message #537882] Mon, 02 January 2012 06:06 Go to previous messageGo to next message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Shouldn't the content type be "text/plain" not just "text"?

Regards
Michel
Re: UTL_MAIL to work with UTF-8 [message #537884 is a reply to message #537883] Mon, 02 January 2012 06:18 Go to previous messageGo to next message
wtfn00b
Messages: 115
Registered: October 2011
Location: Latvia
Senior Member
I put "text/plain" and utf-8 change to windows-1257 and it works now Smile

Best regards,
wtfn00b.
Re: UTL_MAIL to work with UTF-8 [message #537885 is a reply to message #537884] Mon, 02 January 2012 06:49 Go to previous message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Phew! /forum/fa/1704/0/

Regards
Michel
Previous Topic: Hierarchical Query
Next Topic: Check file on viruses
Goto Forum:
  


Current Time: Fri Sep 12 09:35:45 CDT 2025