Email footer image blurred (not every) Oracle PL/SQL

44 Views Asked by At

I created procedure to send mail via pl/sql oracle. I add image (.png) as attachment to mail and open it in mail footer (company logo). Most of mails are correct but sometimes image in footer is blurred. I don't know how fix it :/ This is example of incorrect footer image: Incorrect footer image

This is part of code with footer and attachment

    UTL_SMTP.write_data(v_connection, 'MIME-Version: 1.0' || UTL_TCP.crlf);
  UTL_SMTP.write_data(v_connection,
                      'Content-Type: multipart/mixed; boundary="' ||
                      c_mime_boundary || '"' || UTL_TCP.crlf);

  UTL_SMTP.write_data(v_connection, UTL_TCP.crlf);
  UTL_SMTP.write_data(v_connection,
                      'This is a multi-part message in MIME format.' ||
                      UTL_TCP.crlf);

  UTL_SMTP.write_data(v_connection,
                      '--' || c_mime_boundary || UTL_TCP.crlf);
  UTL_SMTP.write_data(v_connection,
                      'Content-Type: text/html; charset="UTF-8"' ||
                      UTL_TCP.crlf);

                      
 

  UTL_SMTP.write_data(v_connection, UTL_TCP.CRLF);

   -----------------------------------   
  
  
  

    ClobLen := DBMS_LOB.GETLENGTH(p_message);
    
      LOOP
        EXIT WHEN offset > ClobLen;
        DBMS_LOB.READ(p_message || '<br><br>' || p_footer
        , amount, offset, BUFFER);
        UTL_SMTP.write_raw_data(v_connection, UTL_RAW.cast_to_raw(BUFFER));
        offset := offset + amount;
      END LOOP;
      
         UTL_SMTP.write_data(v_connection, UTL_TCP.CRLF);
    
      
      IF p_attach_name IS NOT NULL THEN
        UTL_SMTP.write_data(v_connection, '--' || c_mime_boundary || UTL_TCP.crlf);
        UTL_SMTP.write_data(v_connection, 'Content-Type: ' || p_attach_mime || '; name="' || p_attach_name || '"' || UTL_TCP.crlf);
        UTL_SMTP.write_data(v_connection, 'Content-Transfer-Encoding: base64' || UTL_TCP.crlf);
    
    
        UTL_SMTP.write_data(v_connection, 'Content-Disposition: attachment; filename="' || p_attach_name || '"' || UTL_TCP.crlf || UTL_TCP.crlf);
        
     FOR i IN 0 .. TRUNC((DBMS_LOB.getlength(p_attach_blob) - 1 )/offset) LOOP
          UTL_SMTP.write_data(v_connection, UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(DBMS_LOB.substr(p_attach_blob, offset, i * offset + 1))) || UTL_TCP.crlf);
        END LOOP;
    
        UTL_SMTP.write_data(v_connection, UTL_TCP.crlf);
      END IF;
       -----------------------------------
    
      UTL_SMTP.close_data(v_connection);
      UTL_SMTP.quit(v_connection);
2

There are 2 best solutions below

0
MT0 On

There are multiple places where errors could occur and you need to do some debugging to work out where the error is coming from.

Compare the bytes of the image in the database to the bytes of the image in the received e-mail message - are they identical?

  • If so then the problem either:

    1. The image stored in the database is blurry; or
    2. The e-mail client cannot display the image.

    In both cases this is a data problem and not a code problem.

  • If not then you have a problem somewhere between the database and the recipient.

In the latter case, compare the database bytes with the bytes in the sent email - are they identical?

  • If they are then you have a problem upstream and somehow the e-mail is getting mangled so the image you think you are sending is not being correctly received; this could be a client issue or a network issue or a server configuration issue.
  • If they are not identical then you have an issue either reading from the database or in creating the e-mail.

In the latter case, compare the data put into the database with the data read from the database.

  • If they are identical then you have an error in how you are creating your e-mail.
  • If they are not identical then the data is being transformed either when it is being INSERTed or when it is being SELECTed and you need to find out which.
0
noUserName97 On

I changed img extension to .tif and it solved the problem and you had right @MT0 bytes of the image in received message was 4x smaller than on database