utl_smtp发送1kb图像附件

时间:2018-09-06 08:24:13

标签: oracle plsql oracle11g

我需要发送html消息,并为此附加一个特定的图像。已经做了html消息部分,现在我仍然需要将该图像发送到电子邮件,但是我只收到1kb的附件。

我真的不明白我在做什么错。尝试了很多方法,但我不知道。

任何想法都可以帮助我。谢谢!

a和b只是被屏蔽的值,我没有像这样使用它。

create or replace procedure send_html_utl_mail(p_from                IN VARCHAR2,
                                               p_to                  IN VARCHAR2,
                                               p_cc                  IN VARCHAR2 default null,
                                               p_subject             IN VARCHAR2,
                                               p_body                IN VARCHAR2,
                                               p_attach_name         IN VARCHAR2 DEFAULT NULL,
                                               p_attach_mime         IN VARCHAR2 DEFAULT NULL,
                                               p_attach_blob         IN BLOB DEFAULT NULL)
is
    l_conn              utl_smtp.connection;
    l_boundary          varchar2(32) := sys_guid();
    l_counter           pls_integer;
    l_length            pls_integer;
    buff_size           pls_integer := 57;
    l_raw               raw(57);
begin
    -- Connect
    l_conn := utl_smtp.open_connection( <a> );
    utl_smtp.helo( l_conn, '<b>' );
    utl_smtp.mail( l_conn, p_from );
    utl_smtp.rcpt( l_conn, p_to );
    utl_smtp.open_data(l_conn);

    -- Header
    utl_smtp.write_data( l_conn, 'From: ' || p_from || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, 'To: ' || p_to || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, 'CC: ' || p_cc || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, 'Subject: ' || p_subject || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, 'MIME-Version: 1.0' || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, 'Content-Type: multipart/mixed; ' || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, ' l_boundary= "' || l_boundary || '"' || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, utl_tcp.crlf );

    -- Body
    utl_smtp.write_data( l_conn, '--' || l_boundary || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, 'Content-type:text/html;' || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, ' charset=iso-8859-1' || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, utl_tcp.crlf );
    utl_smtp.write_data( l_conn, p_body || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, utl_tcp.crlf );

    -- Attachment
    utl_smtp.write_data ( l_conn,  '--' || l_boundary || utl_tcp.crlf );
    utl_smtp.write_data ( l_conn,  'Content-Type: '|| p_attach_mime ||';'|| utl_tcp.crlf );
    utl_smtp.write_data ( l_conn, 'Content-Disposition: inline; filename="'|| p_attach_name ||'"' || utl_tcp.crlf);  
    utl_smtp.write_data ( l_conn, 'Content-Transfer-Encoding' || ': ' || 'base64' || utl_tcp.crlf);
    utl_smtp.write_data ( l_conn, utl_tcp.crlf);
    l_counter := 1;
    l_length := dbms_lob.getlength(p_attach_blob);
    while l_counter < l_length loop
        dbms_lob.read(p_attach_blob, buff_size, l_counter, l_raw);
        utl_smtp.write_raw_data( l_conn, utl_encode.base64_encode(l_raw));
        utl_smtp.write_data( l_conn, utl_tcp.crlf);
        l_counter := l_counter + buff_size;
    end loop;
    utl_smtp.write_data( l_conn, utl_tcp.crlf);

    -- Close Email
    utl_smtp.write_data( l_conn, '--' || l_boundary || '--' || utl_tcp.crlf );
    utl_smtp.write_data( l_conn, utl_tcp.crlf || '.' || utl_tcp.crlf );
    utl_smtp.close_data( l_conn );
    utl_smtp.quit( l_conn );    
end;

0 个答案:

没有答案