2016-08-05 4 views
0

せずにPL/SQLを使用してメールを送信:は、SMTPを使用する以外はオラクルからの電子メールを送信するために他の方法がありますSMTP

を親切にいくつかの例可能であれば、どのような方法がある場合は私に知らせてください。

+0

でメールを送信します。 SMTPプロトコルまたはSMTPサーバーを使用しないでください。 –

+0

Hey Alex .. SMTPサーバーを使用しない –

+1

代わりに、MailgunのようなRESTスタイルのAPIを提供するメールゲートウェイを使用する方法もあります。私はあなたが興味を持っているかもしれない郵便銃のためのPL/SQL APIに取り組んでいます:https://github.com/jeffreykemp/mailgun-plsql-api –

答えて

1

Starting from Oracle 8i release 8.1.6, one can send E-mail messages directly from PL/SQL using either the UTL_TCP or UTL_SMTP packages.

あなたはUTL_SMTPパッケージを避ける意味でくださいUTL_TCP

CREATE OR REPLACE PROCEDURE SEND_MAIL (
    msg_from varchar2 := 'oracle', 
    msg_to  varchar2, 
    msg_subject varchar2 := 'E-Mail message from your database', 
    msg_text varchar2 := ) 
IS 
    c utl_tcp.connection; 
    rc integer; 
BEGIN 
    c := utl_tcp.open_connection('127.0.0.1', 25);  -- open the SMTP port 25 on local machine 
    dbms_output.put_line(utl_tcp.get_line(c, TRUE)); 
    rc := utl_tcp.write_line(c, 'HELO localhost'); 
    dbms_output.put_line(utl_tcp.get_line(c, TRUE)); 
    rc := utl_tcp.write_line(c, 'MAIL FROM: '||msg_from); 
    dbms_output.put_line(utl_tcp.get_line(c, TRUE)); 
    rc := utl_tcp.write_line(c, 'RCPT TO: '||msg_to); 
    dbms_output.put_line(utl_tcp.get_line(c, TRUE)); 
    rc := utl_tcp.write_line(c, 'DATA');     -- Start message body 
    dbms_output.put_line(utl_tcp.get_line(c, TRUE)); 
    rc := utl_tcp.write_line(c, 'Subject: '||msg_subject); 
    rc := utl_tcp.write_line(c,); 
    rc := utl_tcp.write_line(c, msg_text); 
    rc := utl_tcp.write_line(c, '.');     -- End of message body 
    dbms_output.put_line(utl_tcp.get_line(c, TRUE)); 
    rc := utl_tcp.write_line(c, 'QUIT'); 
    dbms_output.put_line(utl_tcp.get_line(c, TRUE)); 
    utl_tcp.close_connection(c);       -- Close the connection 
END; 
/

-- Test it: 
set serveroutput on 

exec send_mail(msg_to =>'[email protected]'); 

exec send_mail(msg_to =>'[email protected]', - 
      msg_text=>'Look Ma, I can send mail from plsql' - 
      ); 
+0

ありがとうございます!あなたの助けを借りて、それを動作させるためには環境内の任意の設定を有効にする必要がありますか?SMTPは無効になっているか、テスト環境にインストールされていません。親切に –

+0

のポート25のステータスを確認する必要があります https://www.siteground.com/kb/smtp_port_25_blocked/ – are

関連する問題