就是在原有TOM源码的基础上修改utl_smtp.write_data中,将输出内容进行一下数据转换,这样可以保证中文输出不会出现乱码
-----------------------------
create or replace procedure html_email(
p_to in varchar2,
p_from in varchar2,
p_subject in varchar2,
p_text in varchar2 default null,
p_html in varchar2 default null,
p_smtp_hostname in varchar2,
p_smtp_portnum in varchar2)
is
l_boundary varchar2(255) default 'a1b2c3d4e3f2g1';
l_connection utl_smtp.connection;
l_body_html clob := empty_clob; --This LOB will be the email message
l_offset number;
l_ammount number;
l_temp varchar2(32767) default null;
begin
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); ----------------------------------------------------
-- Write the headers
dbms_lob.createtemporary( l_body_html, false, 10 );
dbms_lob.write(l_body_html,length(l_temp),1,l_temp); ----------------------------------------------------
-- Write the text boundary
l_offset := dbms_lob.getlength(l_body_html) + 1;
l_temp := '--' || l_boundary || chr(13)||chr(10);
l_temp := l_temp || 'content-type: text/plain; charset=us-ascii' ||
chr(13) || chr(10) || chr(13) || chr(10);
dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp); ----------------------------------------------------
-- Write the plain text portion of the email
l_offset := dbms_lob.getlength(l_body_html) + 1;
dbms_lob.write(l_body_html,length(p_text),l_offset,p_text); ----------------------------------------------------
-- Write the HTML boundary
l_temp := chr(13)||chr(10)||chr(13)||chr(10)||'--' || l_boundary ||
chr(13) || chr(10);
l_temp := l_temp || 'content-type: text/html;' ||
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); ----------------------------------------------------
-- Write the HTML portion of the message
l_offset := dbms_lob.getlength(l_body_html) + 1;
dbms_lob.write(l_body_html,length(p_html),l_offset,p_html); ----------------------------------------------------
-- Write the final html boundary
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); ----------------------------------------------------
-- Send the email in 1900 byte chunks to UTL_SMTP
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));
UTL_SMTP.WRITE_RAW_DATA(L_CONNECTION,UTL_RAW.cast_to_raw(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);
end;
/
show errors

使用UTL_SMTP发送中文电子邮件的更多相关文章

  1. Oracle 10G 使用UTL_SMTP发送中文电子邮件[Z]

    CREATE OR REPLACE PROCEDURE SCOTT.HTML_EMAIL( P_TO IN VARCHAR2, --收件人地址 P_SUBJECT IN VARCHAR2, --邮件主 ...

  2. 使用UTL_SMTP发送中文邮件及使用UTL_TCP从附件服务器获取中文附件

    先上最重要的干货 发送邮件正文及主题的时候一定要使用convert重新编码 主题: utl_smtp.write_raw_data(l_mail_conn, utl_raw.cast_to_raw(c ...

  3. Servlet向客户端发送中文数据的编码情况

    (更多内容请关注本人微信订阅号:it_pupil) 本文讲述服务端servlet向客户端浏览器发送中文数据的编码情况,需要抓住下面几点: 输出流发送数据,必须是以字节形式传输的.也就是说,如果你在服务 ...

  4. AT命令text模式发送中文

    AT命令text模式发送中文 AT+CSCS=? 查询支持哪些编码 设置编码和编码格式等 AT+CMGF=1 //TEXT 模式 //AT+CSCS="UCS2" //设置编码 A ...

  5. C# Socket的方式发送中文,接收方收到乱码

    场景: 使用 Socket的方式向下位机发送中文信息,下位机收到的中文是乱码 原因: 了解到的原因是上位机与下位机的发送与接收的编码与解码方式不一致 比如上位机采用 Encoding.UTF8.Get ...

  6. UDP发送中文

    procedure TForm1.SpeedButton1Click(Sender: TObject); begin udp.Send('localhost', 1234, 'abc123'); // ...

  7. ASP.NET 3.5 中实现发送email电子邮件

    来源:红黑联盟 方法1:cs代码 using System.Net.Mail; using System.Net; string mailServerName = "smtp.qq.com& ...

  8. Yii Swiftmailer 发送中文附件

    所用的是Yii2 的basic框架.它本身集成了邮件发送插件swiftmailer,发送邮件是很方便的,但是当发送的邮件带有中文名称的附件时,就出现了问题,邮件所带的附件显示名称错误.比如原名&quo ...

  9. ie11下ajax用escape发送中文参数失败

    一个项目中,登录请求是ajax,get模式.登录名无中文可以正常登录:登录名是中文则偶尔可以登录,大部分情况下无法登录,ajax请求无法发送成功. 登录名是用js的escape函数转码. 经过多次测试 ...

随机推荐

  1. WCF Rest:不使用UriTemplate使用post方式传参解决HTTP400问题以及参数映射问题

    在使用POST方式向服务提交数据时,出现HTTP400异常,以下代码描述: 服务接口定义: [OperationContract] [WebInvoke(ResponseFormat = WebMes ...

  2. Sql Server 2012启动存储过程

    可以通过如下步骤创建 1.打开show advanced options reconfigure 2.打开scan for startup procs,使得sql server在启动时扫描需要运行的p ...

  3. 关于meta定义 和 link

    <!DOCTYPE html> <!-- HTML5 doctype 不区分大小写 --> <html lang="zh-cmn-Hans-CN"&g ...

  4. 轻松搞定Ajax(分享下自己封装ajax函数,其实Ajax使用很简单,难是难在你得到数据后来怎样去使用这些数据)

    hey,guys!今天我们一起讨论下ajax吧!此文只适合有一定ajax基础,但还是模糊状态的同志,当然高手也可以略过~~~ 一.概念 Ajax(Asynchronous Javascript + X ...

  5. View的工作原理(二)——layout

    1.当View的measure被确定后,会调用ViewGroup的layout方法,之后使用onLayout方法(同样也是系统未自动重写,要我们自己完成)遍历子View(根Measure的形式是一样得 ...

  6. placeholder在不同浏览器下的表现及兼容方法 placeholder兼容

    1.什么是placeholder?    placeholder是html5新增的一个属性,当input或者textarea设置了该属性后,该值的内容将作为灰字提示显示在文本框中,当文本框获得焦点(或 ...

  7. BCB6.0(Borland C++ Builder 6.0)下载位置(P2P)

    这个老东西还真不好找,搜索了一下,有一些所谓的精简版,绿色版,破解版,不靠谱. 公司有正版光盘,我装过,下面这两个应该是原版的: CD1: ed2k://|file|%5BBorland.C...Bu ...

  8. qt 自动完成LineEdit

    原地址:http://www.cppblog.com/biao/archive/2009/10/31/99873.html     ---------------------------------- ...

  9. Windows Components Reference(Windows组件参考)

    原文 http://www.msfn.org/board/topic/127287-windows-components-reference/ green means the component na ...

  10. ViewPager+Fragment取消预加载(延迟加载)

    在项目中,都或多或少地使用的Tab布局,所以大都会用到ViewPager+Fragment,但是Fragment有个不好或者太好的地方.例如你在ViewPager中添加了三个Fragment,当加载V ...