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 に答える