1

我的 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 */

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

4

1 回答 1

1

文档中提到了该错误,该文档还告诉您如何使用 SSL/TLS 保护 SMTP 连接。你需要打电话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);
    ...
于 2016-11-17T12:38:58.523 回答