使用UTL_SMTP发送中文电子邮件
就是在原有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发送中文电子邮件的更多相关文章
- Oracle 10G 使用UTL_SMTP发送中文电子邮件[Z]
CREATE OR REPLACE PROCEDURE SCOTT.HTML_EMAIL( P_TO IN VARCHAR2, --收件人地址 P_SUBJECT IN VARCHAR2, --邮件主 ...
- 使用UTL_SMTP发送中文邮件及使用UTL_TCP从附件服务器获取中文附件
先上最重要的干货 发送邮件正文及主题的时候一定要使用convert重新编码 主题: utl_smtp.write_raw_data(l_mail_conn, utl_raw.cast_to_raw(c ...
- Servlet向客户端发送中文数据的编码情况
(更多内容请关注本人微信订阅号:it_pupil) 本文讲述服务端servlet向客户端浏览器发送中文数据的编码情况,需要抓住下面几点: 输出流发送数据,必须是以字节形式传输的.也就是说,如果你在服务 ...
- AT命令text模式发送中文
AT命令text模式发送中文 AT+CSCS=? 查询支持哪些编码 设置编码和编码格式等 AT+CMGF=1 //TEXT 模式 //AT+CSCS="UCS2" //设置编码 A ...
- C# Socket的方式发送中文,接收方收到乱码
场景: 使用 Socket的方式向下位机发送中文信息,下位机收到的中文是乱码 原因: 了解到的原因是上位机与下位机的发送与接收的编码与解码方式不一致 比如上位机采用 Encoding.UTF8.Get ...
- UDP发送中文
procedure TForm1.SpeedButton1Click(Sender: TObject); begin udp.Send('localhost', 1234, 'abc123'); // ...
- ASP.NET 3.5 中实现发送email电子邮件
来源:红黑联盟 方法1:cs代码 using System.Net.Mail; using System.Net; string mailServerName = "smtp.qq.com& ...
- Yii Swiftmailer 发送中文附件
所用的是Yii2 的basic框架.它本身集成了邮件发送插件swiftmailer,发送邮件是很方便的,但是当发送的邮件带有中文名称的附件时,就出现了问题,邮件所带的附件显示名称错误.比如原名&quo ...
- ie11下ajax用escape发送中文参数失败
一个项目中,登录请求是ajax,get模式.登录名无中文可以正常登录:登录名是中文则偶尔可以登录,大部分情况下无法登录,ajax请求无法发送成功. 登录名是用js的escape函数转码. 经过多次测试 ...
随机推荐
- PHP学习笔记1.1——date()函数的多种用法,取出各种不同格式的时间,非常全面
语法格式:date(string format.int timestamp); 参数一:format指定输出的日期和时间的格式,具体的参见下表; 参数二:timestamp是可选参数,是时间戳,如果不 ...
- android——ObjectAnimator动画(一)
直接贴上集中用法 package com.example.test; import com.example.test.views.CircleView; import android.animatio ...
- HTML之学习笔记(二)颜色体系
html页面的颜色表示法有三种:英文表示,16进制表示和10进制表示.颜色通过三原色即红.绿.蓝三种按比例混合而成,如红色的10进制表示为255,0,0,即按照红色.绿色.蓝色的格式,权值取0~255 ...
- js打印数据类型
console.log({}.toString.call(123))--- [object Number].... [object String] [object Undefined] [object ...
- JavaScript面向对象精要
来自:淡忘~浅思. 链接:http://www.ido321.com/1585.html 和 http://www.ido321.com/1586.html 数据类型 在JavaScript中,数 ...
- 认证和注册,提交到App Store:
账号分为个人和公司个人付费后2天左右,收到激活邮件,可以使用 member center certificates,identifiers&profiles:certificates 认证:d ...
- 地图:CLGeocoder地址解析与反地址解析
1.导入系统框架
- SQL Performance Improvement Techniques(转)
原文地址:http://www.codeproject.com/Tips/1023621/SQL-Performance-Improvement-Techniques This article pro ...
- golang illegal base64 data at input byte
//one reason is whitespace ciphertext = strings.Replace(ciphertext, " ", "", -1) ...
- [Linux Kernel]查看CentOS版本方法
查看CentOS版本方法 有以下命令可以查看: # lsb_release -a LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics- ...