DECLARE
  c Utl_Smtp.connection;

  PROCEDURE send_header(NAME IN VARCHAR2, HEADER IN VARCHAR2) AS
  BEGIN
    Utl_Smtp.write_data(c, NAME || ': ' || HEADER || Utl_Tcp.CRLF);
  END;

BEGIN
  c := Utl_Smtp.open_connection('192.168.1.10');
  Utl_Smtp.helo(c, 'vishalgupta.co.uk');
  Utl_Smtp.mail(c, 'vishal@vishalgupta.co.uk');
  Utl_Smtp.rcpt(c, 'vishal@vishalgupta.co.uk');
  Utl_Smtp.open_data(c);
  send_header('From',    '"Sender" <vishal@vishalgupta.co.uk>');
  send_header('To',      '"Recipient" <vishal@vishalgupta.co.uk>');
  send_header('Subject', 'Hello');
  Utl_Smtp.write_data(c, Utl_Tcp.CRLF || 'Hello, world!');
  Utl_Smtp.close_data(c);
  Utl_Smtp.quit(c);
EXCEPTION
  WHEN Utl_Smtp.transient_error OR Utl_Smtp.permanent_error THEN
    Utl_Smtp.quit(c);
    RAISE_APPLICATION_ERROR(-20000,
      'Failed to send mail due to the following error: ' || SQLERRM);
END;
/

