PL/SQL 发送带有附件的电子邮件吗?
我们有一个表,其中文件保存为 BLOB
我编写了一个代码,将这些文件作为附件通过电子邮件发送!
到目前为止,一切工作正常,但程序无法读取文件(EXCEL、PDF...等等),只有文本文件和 Excel 会打开,但在出现一些错误消息后,PDF 根本无法打开!
这是有问题的代码部分!
utl_smtp.write_data( l_connection, '--'|| l_boundary || utl_tcp.crlf);
utl_smtp.write_data( l_connection, 'Content-Type: application/octet-stream' || utl_tcp.crlf);
utl_smtp.write_data( l_connection, 'Content-Disposition: attachment; filename="' || V_NAME || '"' || utl_tcp.crlf);
utl_smtp.write_data( l_connection, 'Content-Transfer-Encoding: base64' || utl_tcp.crlf );
utl_smtp.write_data( l_connection, utl_tcp.crlf );
v_length := dbms_lob.getlength(V_BLOB_CONTENT);
while v_offset < v_length loop
dbms_lob.read( V(i).BLOB_CONTENT, v_buffer_size, v_offset, v_raw );
utl_smtp.write_raw_data( l_connection, utl_encode.base64_encode(v_raw) );
utl_smtp.write_data( l_connection, utl_tcp.crlf );
v_offset := v_offset + v_buffer_size;
end loop while_loop;
utl_smtp.write_data( l_connection, utl_tcp.crlf );
有什么建议吗?
we have a table with files saved as BLOB
I write a code that email these files as an attachment!
everything works fine so far, but the files (EXCEL,PDF, ... what ever) are not readable by the programs, only text files and excel will open but after some error message, where PDFs all not be opened at all!
here is the part of the code in question!
utl_smtp.write_data( l_connection, '--'|| l_boundary || utl_tcp.crlf);
utl_smtp.write_data( l_connection, 'Content-Type: application/octet-stream' || utl_tcp.crlf);
utl_smtp.write_data( l_connection, 'Content-Disposition: attachment; filename="' || V_NAME || '"' || utl_tcp.crlf);
utl_smtp.write_data( l_connection, 'Content-Transfer-Encoding: base64' || utl_tcp.crlf );
utl_smtp.write_data( l_connection, utl_tcp.crlf );
v_length := dbms_lob.getlength(V_BLOB_CONTENT);
while v_offset < v_length loop
dbms_lob.read( V(i).BLOB_CONTENT, v_buffer_size, v_offset, v_raw );
utl_smtp.write_raw_data( l_connection, utl_encode.base64_encode(v_raw) );
utl_smtp.write_data( l_connection, utl_tcp.crlf );
v_offset := v_offset + v_buffer_size;
end loop while_loop;
utl_smtp.write_data( l_connection, utl_tcp.crlf );
any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我用来执行的一个过程,
我用它来将多个附件添加到单个电子邮件中。对我来说就像冠军一样。
一件事是,p_boundary 被传入为
我看到您已经有一个 l_boundary,这就是您应该使用的。
这也基于 http://christopherbeck.wordpress.com/category/plsql/作为 http://www.oracle-base.com/articles/misc/EmailFromOraclePLSQL.php#attachment
。
然后在您的代码中,只需传入您的 smtp 连接、l_boundary(即 RAW sys_guid 或您正在使用的任何内容)、文件名(它将出现在电子邮件附件中)和 BLOB。
*编辑 - -> 附加信息 *
我们的假设相同:
但是我注意到,您必须遵循一个顺序才能使其正常工作(特别是,将附件放在正文之后的 END 旁边!!!
here is a procedure that I use to do just that
I use this to add multiple attachments to a single email. works like a champ for me.
one thing, the p_boundary is passed in as
I see that you already have an l_boundary and that is what you should use.
this is based on http://christopherbeck.wordpress.com/category/plsql/ as well as http://www.oracle-base.com/articles/misc/EmailFromOraclePLSQL.php#attachment
.
then in your code, just pass in your smtp connection, the l_boundary (ie RAW sys_guid or whatever you are using, the name of the file (as it will appear on the email attachment), and the BLOB.
*EDIT --> additional information *
Ours are the same with the assumption of:
But I have noticed that there is an order that you must follow to get it to work (notably, put the attachments next to the END after body!!!
Tim Hall 有一个很棒的网站 (oracle-base),其中包含你在寻找什么。特别注意编码是如何完成的。
我使用类似的代码通过 pl/sql 发送电子邮件没有问题
Tim Hall has a great site (oracle-base) that has what you're looking for. Note in particular how the encoding is done.
I've used similar code to send emails via pl/sql without problem