Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Oracle > Как в PL/SQL отослать письмо?


Автор: dron000 2.11.2006, 15:13
Использую пакет dbms_ , токо вот проблеиа как отослать письмо если на сервере требуется аунтификация? т.е. как передавать логин и пароль?

Автор: LSD 2.11.2006, 16:43
"Нормальных" способов похоже, нет. Есть один через ...:
Цитата
We are using SMTP Authentication. Is there a way I could provide username and 
password to the smtp server via pl/sql.

SQL> execute send_mail('[email protected]','[email protected]','this is a test');
BEGIN send_mail('[email protected]','[email protected]','this is a test'); END;

*
ERROR at line 1:
ORA-29279: SMTP permanent error: 530 Authentication Required
ORA-06512: at "SYS.UTL_SMTP", line 17
ORA-06512: at "SYS.UTL_SMTP", line 98
ORA-06512: at "SYS.UTL_SMTP", line 240
ORA-06512: at "SCOTT.SEND_MAIL", line 11
ORA-06512: at line 1

Thanks 

Followup:
you can write directly to the SMTP server and do the authorization, yes.

just telnet to your SMTP server (telnet hostname 25) and type HELP

> telnet aria 25
Trying 138.2.5.51...
Connected to aria.
Escape character is '^]'.
220 aria-lnx.us.oracle.com ESMTP Sendmail 8.11.6/8.11.6; Wed, 16 Jun 2004 
12:02:18 -0400
HELP
214-2.0.0 This is sendmail version 8.11.6
214-2.0.0 Topics:
214-2.0.0       HELO    EHLO    MAIL    RCPT    DATA
214-2.0.0       RSET    NOOP    QUIT    HELP    VRFY
214-2.0.0       EXPN    VERB    ETRN    DSN     AUTH
214-2.0.0       STARTTLS
214-2.0.0 For more info use "HELP <topic>".
214-2.0.0 To report bugs in the implementation send email to
214-2.0.0       [email protected].
214-2.0.0 For local information send email to Postmaster at your site.
214 2.0.0 End of HELP info


You'll see a list of commands it supports.  from there, you'll have to figure 
out the protocol your server is using to authenticate (should be able to google 
that up, some rfc somewhere)....

then you can use utl_smtp to write that information to the SMTP server. 

(взято http://asktom.oracle.com/pls/ask/f?p=4950:12:3265168590965219730::NO::F4950_P12_DATE_YYYYMMDD:20050917)

Или использовать хранимые процедуры на Java.

Автор: batigoal 3.11.2006, 09:21
У нас авторизация для отсылки письма сделана через LDAP, но я не в курсе подробностей.

Автор: Paradox 3.11.2006, 09:54
я один раз делал отправку мыла через PL/SQL
по образу и подобию вот этого (все работало, исходник с SQL.ru)
Код

declare
  sender varchar2(80) := '[email protected]';
  recipient varchar2(80) := '[email protected]';
  smtpHost varchar2(80) := 'smtp.yandex.ru';
  smtpUser varchar2(256) := 'denislpopov';
  smtpPassword varchar2(256) := '<password>';

  mail_conn utl_smtp.connection;
  separator varchar2(1) := ' ';
  content_charset varchar2(8) := 'koi-8r';

  procedure send_header(name in varchar2, header in varchar2) as
  begin
    utl_smtp.write_raw_data(mail_conn, UTL_RAW.cast_to_raw(name||': '||header||utl_tcp.CRLF));
  end;

begin
  mail_conn := utl_smtp.open_connection(smtpHost, 25);
  utl_smtp.helo(mail_conn, smtpHost);
  -- If Authentication required for SMTP
  -- After upgrade to Oracle 9i, replace demo_base64.encode 
  -- with the native utl_encode.base64_encode for better performance.
  utl_smtp.command(mail_conn, 'AUTH LOGIN');
  utl_smtp.command(
      mail_conn
    , utl_raw.cast_to_varchar2(
        utl_encode.base64_encode(utl_raw.cast_to_raw(smtpUser))
      )
  );
  utl_smtp.command(
      mail_conn
    , utl_raw.cast_to_varchar2(
        utl_encode.base64_encode(utl_raw.cast_to_raw(smtpPassword))
      )
  );

  utl_smtp.mail(mail_conn, sender);
  utl_smtp.rcpt(mail_conn, recipient);
  utl_smtp.open_data(mail_conn);
  send_header('From', sender);
  send_header('To', recipient);
  send_header('CC', recipient);
  send_header('Subject', 'Test Проверка');
  send_header('MIME-Version', '1.0');
  send_header('Content-Type', 'text/plain; charset="'||content_charset||'"');

  utl_smtp.write_raw_data(
      mail_conn
    , utl_raw.cast_to_raw(utl_tcp.CRLF||'Графиня изменившимся лицом бежит пруду')
  );

  utl_smtp.close_data(mail_conn);
  utl_smtp.quit(mail_conn);
end;
/



Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)