How to send email from Oracle Apex using MailGun

What:

  1. You successfully created your smtp server using mailgun.com enter image description here

  2. You would like to configure your MailGun SMTP server in Oracle Apex ( 4.x and above ) ?

Upvotes: 1

Views: 1538

Answers (1)

HOW

   SMTP Host Address : smtp.mailgun.org [ MUST use this one and NOT yours ] 
   SMTP Host Port : 587
   Use SSL/TLS : No [ important ]
   SMTP Authentication Username   : [email protected]
   SMTP Authentication Password   : 2118870544b548867c2258f318fba6dd-9949a98f-201cc5b5 [ see in image below ] 
   Default Email From Address     : [email protected]

enter image description here enter image description here

  • Database ACL settings to be applied ( you may use the code below - credits )
-- to be run as user SYS

-- to avoid ORA-30992 and ORA-01858 due to invalid date format when calling create_acl
alter session set nls_language = AMERICAN;
alter session set nls_territory = AMERICA;

BEGIN
  DBMS_NETWORK_ACL_ADMIN.create_acl (
    acl          => 'apex.xml', 
    description  => 'Access Control List for APEX',
    principal    => 'APEX_050000',
    is_grant     => TRUE, 
    privilege    => 'connect',
    start_date   => SYSTIMESTAMP,
    end_date     => NULL);
  COMMIT;
END;
/

-- for outgoing mail via local mail server

BEGIN
  DBMS_NETWORK_ACL_ADMIN.assign_acl (
    acl         => 'apex.xml',
    host        => 'localhost', 
    lower_port  => 25,
    upper_port  => 25); 
  COMMIT;
END;
/

-- for integration to PayPal (also requires Oracle Wallet with SSL certificate)

BEGIN
  DBMS_NETWORK_ACL_ADMIN.assign_acl (
    acl         => 'apex.xml',
    host        => '*.paypal.com', 
    lower_port  => 443,
    upper_port  => 443); 
  COMMIT;
END;
/

-- for integration with Amazon S3 (use port 443 if using SSL)

BEGIN
  DBMS_NETWORK_ACL_ADMIN.assign_acl (
    acl         => 'apex.xml',
    host        => '*.amazonaws.com', 
    lower_port  => 80,
    upper_port  => 80); 
  COMMIT;
END;
/

/*

-- add another user/schema to already existing ACL

BEGIN
  DBMS_NETWORK_ACL_ADMIN.add_privilege ( 
    acl         => 'apex.xml', 
    principal   => 'YOUR_SCHEMA_NAME',
    is_grant    => TRUE, 
    privilege   => 'connect', 
    position    => NULL, 
    start_date  => NULL,
    end_date    => NULL);

  COMMIT;
END;
/

*/


-- to verify settings:
select host, lower_port, upper_port, acl
from dba_network_acls;

select *
from dba_network_acl_privileges;
  • Test it :
apex_mail.send(
        p_to       => '[email protected]' ,   -- change to your email address
        p_from     => '[email protected]', -- change to a real senders email address
        p_body     => 'test',
        p_body_html => '<html><body>test</body></html>',
        p_subj     => 'test mailgun');

Upvotes: 1

Related Questions