Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Mail problem with long titles using utl_smtp / mixed content / attachements

663055Mar 8 2011 — edited Mar 9 2011
Hello,

I'm having a problem with sending emails. The title as well as the body needs to be able to contain accented letters (é ç ...).

For the body i got it working.
And the title works fine too, untill the encoding passes a certain length, then goes all wrong and my mail header starts showing up in the mail body.

Could anyone help me in finding a solution?

Thanks in advance

Below my code:
DECLARE

   v_From       VARCHAR2(80) := 'test@localhost';

   v_Recipient  VARCHAR2(80) := 'test@localhost';
   v_Cc         VARCHAR2(80);
-- long subject causing problems
   v_Subject    VARCHAR2(32000) := '123456789111111111111111111111118888888888888111111111111111991234567891111111111111111111111188888888888881111111111111119912345678911111111111111111111111888888888888811111111111111199'; 
   v_body       VARCHAR2(32000) := '<a href="#">tester</a><br><br>en nog wat éékes en ççkes';
   v_Mail_Host  VARCHAR2(30) := 'localhost'; 
   v_Mail_Conn  utl_smtp.Connection;
   crlf         VARCHAR2(2)  := chr(13)||chr(10);

BEGIN

  v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host, 25);
  utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);
  utl_smtp.Mail(v_Mail_Conn, v_From);
  utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);

  utl_smtp.Data(v_Mail_Conn,
-- write header
    'Date: '   || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||
    'From: '   || v_From || crlf ||
    'Subject: ' || utl_encode.MIMEHEADER_ENCODE(v_Subject) || crlf ||
    'To: '     || v_Recipient || crlf ||
    'Cc: '     ||  v_Cc || crlf ||
    'X-Mailer: Mailer by Oracle UTL_SMTP' || crlf ||
    'X-Priority: 1' || crlf ||
    'MIME-Version: 1.0'|| crlf ||       -- Use MIME mail standard
    'Content-Type: multipart/mixed;'|| crlf ||
    ' boundary="-----SECBOUND"'|| crlf ||
    crlf || 
-- add message body
    '-------SECBOUND'|| crlf ||
    'Content-type: text/html; charset=UTF-8'|| crlf ||
    'Content-Transfer-Encoding: base64'|| crlf ||
    crlf ||
    utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(v_body)))||
    crlf ||
-- add csv attachment
    '-------SECBOUND'|| crlf ||
    'Content-Type: text/plain;'|| crlf ||
    ' name="excel.csv"'|| crlf ||
    'Content-Transfer_Encoding: 8bit'|| crlf ||
    'Content-Disposition: attachment;'|| crlf ||
    ' filename="excel.csv"'|| crlf ||
    crlf ||
    'CSV,file,attachement'|| crlf ||   -- Content of attachment
    crlf ||
    '-------SECBOUND--'                            -- End MIME mail
  );
  utl_smtp.Quit(v_mail_conn);

EXCEPTION

  WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
    raise_application_error(-20000, 'Unable to send mail: '||sqlerrm);
END;

/
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2011
Added on Mar 8 2011
4 comments
442 views