Roundcube Community Forum

 

How to send an email to API

Started by neroq, March 05, 2025, 10:45:00 PM

Previous topic - Next topic

neroq

I have an API that saves email data to display the outgoing email on the site, I have made this code
// test data
$subject = "Test Subject";
$body = "Test Body";
$from_email = "[email protected]";


$api_data = [
    "subject" => $subject,
    "body" => $body,
    "from_email" => $from_email
];

// send data to API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://myapi/api/receive-email");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($api_data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json'
]);

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);


unlink($cache_file);


echo "HTTP Code: $http_code\n";
echo "Response: $response\n";
how to pass email data from roundcube to API?


JohnDoh

Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more...

neroq

Quote from: JohnDoh on March 06, 2025, 02:45:05 AMhave a look at the message_before_send or the message_sent plugin hooks
I found how to create my custom hook, but in which directory to create it? /usr/share/roundcube/plugins?

SKaero