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

时间:2021-08-02 23:52:21

先上最重要的干货

发送邮件正文及主题的时候一定要使用convert重新编码

主题:

utl_smtp.write_raw_data(l_mail_conn,
utl_raw.cast_to_raw(convert('Subject:' || p_subject || utl_tcp.crlf,
'ZHS16GBK')));

正文内容:

utl_smtp.write_raw_data(l_mail_conn,
utl_raw.cast_to_raw(convert(p_text_msg,
'ZHS16GBK')));

附件类型及头信息

utl_smtp.write_raw_data(l_mail_conn,
utl_raw.cast_to_raw(convert('Content-Type: ' || p_attach_mime || '; name="' ||
p_attach_name || '"' || utl_tcp.crlf,
'ZHS16GBK')));

附件名称

utl_smtp.write_raw_data(l_mail_conn,
utl_raw.cast_to_raw(convert('Content-Disposition: attachment; filename="' ||
p_attach_name || '"' || utl_tcp.crlf || utl_tcp.crlf,
'ZHS16GBK')));

附件路径:

l_file := convert(l_file,
'ZHS16GBK');

附件 send mail with attachment

(顺便鄙视一下博客园,作为一个标榜为技术博客的园子,竟然对附件的支持这么弱,仅IE能下载,chrome和ff都不能下载。并且邮件链接地址还是我自己用F12获取的,不知道是不是我不会用。)

参考资料:

Email From Oracle PL/SQL (UTL_SMTP)

FTP From PL/SQL

How to FTP with Oracle PL/SQL

Sending Mail with Multiple Attachment In PL/Sql(发送邮件带多个附件)