我有一个生产问题涉及Oracle 11g电子邮件发送日期。代码如下所示。Oracle电子邮件发送日期有时不正确
procedure email(p_recip in apex_application_global.vc_arr2,
p_subject in varchar2,
p_message in varchar2) is
c utl_smtp.connection;
msg varchar2(4000);
username varchar2(100) := 'XXX';
password varchar2(100) := '123';
l_encoded_username varchar2(200);
l_encoded_password varchar2(200);
l_recips varchar2(2000);
procedure send_header(name in varchar2, header in varchar2) as
begin
utl_smtp.write_data(c, name || ': ' || header || utl_tcp.crlf);
end;
begin
--Open SMTP connection
l_encoded_username := utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(username)));
l_encoded_password := utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(password)));
c := utl_smtp.open_connection('AAA.BBB.local', '25');
utl_smtp.ehlo(c, 'AAA.BBB.local'); --DO NOT USE HELO
utl_smtp.command(c, 'AUTH', 'LOGIN');
utl_smtp.command(c, l_encoded_username);
utl_smtp.command(c, l_encoded_password);
utl_smtp.mail(c, '[email protected]');
if ((p_recip is null) or p_recip.count = 0) then
return;
end if;
for i in 1 .. p_recip.count loop
utl_smtp.rcpt(c, p_recip(i));
l_recips := l_recips || p_recip(i) || ','; --mark as Multiple receivers
end loop;
--now remove the trailing comma at the end of l_recips
l_recips := substr(l_recips, 0, length(l_recips) - 1);
utl_smtp.open_data(c);
--prepare mail header
utl_smtp.write_data(c, 'Date: ' ||
to_char(sysdate, 'MM-DD-YYYY HH24:MI:SS') ||
utl_tcp.crlf);
utl_smtp.write_data(c, 'To: ' || l_recips || utl_tcp.crlf);
utl_smtp.write_data(c, 'From: ' ||
'"Company" <[email protected]>' ||
utl_tcp.crlf);
utl_smtp.write_data(c, 'Subject: ' || p_subject || utl_tcp.crlf ||
utl_tcp.crlf);
--include the message body
utl_smtp.write_data(c, msg);
-- Write message body
utl_smtp.write_data(c, p_message || utl_tcp.crlf);
-- Clean up
utl_smtp.close_data(c);
utl_smtp.quit(c);
exception
when utl_smtp.transient_error or utl_smtp.permanent_error then
begin
utl_smtp.quit(c);
exception
when utl_smtp.transient_error or utl_smtp.permanent_error then
null;
-- When the SMTP server is down or unavailable, we don't have
-- a connection to the server. The QUIT call will raise an
-- exception that we can ignore.
end;
raise_application_error(-20000, 'Failed to send mail due to the following error: ' ||
sqlerrm);
end;
------------------------------------------
Unfortunately, the date on received email "Sent:" some times are wrong.
For example :
一个是从您的数据库的日期 - 一个是从电子邮件服务器的日期... – Randy