使用 Oracle Linux 7 上的后缀从 Oracle 12c 发送电子邮件

Send email from Oracle 12c with postfix on Oracle Linux 7

我的 Oracle Linux 上有 postfix 服务,它们运行良好。 我使用函数

create or replace procedure Send_Mail(Msg_To varchar2, Msg_Subject varchar2, Msg_Text varchar2) is
    c        Utl_Smtp.Connection;
    Rc       integer;
    Msg_From varchar2(50) := 'me@me.com'; -- email of my company which hosted on Gmail
    Mailhost varchar2(30) := 'smtp.gmail.com';

begin
    c := Utl_Smtp.Open_Connection(Mailhost, 587);
    Utl_Smtp.Helo(c, Mailhost);
    Utl_Smtp.StartTLS(c);
    Utl_Smtp.Mail(c, Msg_From);
    Utl_Smtp.Rcpt(c, Msg_To);

    Utl_Smtp.Data(c,
                  'From: Oracle Database' || Utl_Tcp.Crlf || 'To: ' || Msg_To || Utl_Tcp.Crlf || 'Subject: ' || Msg_Subject || Utl_Tcp.Crlf ||
                  Msg_Text);
    Utl_Smtp.Quit(c);

exception
    when Utl_Smtp.Invalid_Operation then
        Dbms_Output.Put_Line(' Invalid Operation in Mail attempt 
using UTL_SMTP.');
    when Utl_Smtp.Transient_Error then
        Dbms_Output.Put_Line(' Temporary e-mail issue - try again');
    when Utl_Smtp.Permanent_Error then
        Dbms_Output.Put_Line(' Permanent Error Encountered.');
end;

我在 http://www.dba-oracle.com/t_utl_smtp_utility.htm

上找到的

当我运行函数

BEGIN
send_mail(msg_to      => 'me@me.com',
          msg_subject => 'Test subject',
          msg_text    => 'Test text');
END;

我得到一个错误:

ORA-29279: SMTP permanent error: 530 5.7.0 Must issue a STARTTLS command first. im3sm2477330wjb.13 - gsmtp /* 132/5 selected symbols */

我做错了什么或我必须做什么?

错误在文档中提到,它也告诉你how to secure the SMTP connection using SSL/TLS。您需要致电 utl_smtp.starttls().

...
begin
    c := Utl_Smtp.Open_Connection(Mailhost, 587);
    Utl_Smtp.Ehlo(c, Mailhost);
    Utl_Smtp.StartTLS(c);
    Utl_Smtp.Ehlo(c, Mailhost);
    Utl_Smtp.Mail(c, Msg_From);
    Utl_Smtp.Rcpt(c, Msg_To);
    ...