Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
in Q2A Core by
Is it possible to configure Q2A to use a web service API in order to send emails, or is neccesary to make changes on the php code to acomplish this?

The web service has an endpoint in which I can post an email as payload.
Q2A version: 1.8.6
What advantage do you see in using a web service over using regular SMTP?
I think there is not any particular advantage in general. But in my case, I work for a company which only allows you to send mails (in case of using an external app) via a web service. But I agree that using SMTP is in general the right option.

1 Answer

+1 vote
edited by
Best answer

I finally archive this, apperantly q2a does not support the use of web services natively, but I found a workarround editing the file qa-src/Notification/Email.php inside the function sendMessage adding the following code:

$location = "<webserviceURL>";

    $subjectMail = strtr($subject, $fullsubs);

    $userEmail = $this->email;

    $bodyContent = htmlspecialchars(nl2br($bodyPrefix . strtr($body, $fullsubs))); // nl2br is neccesary to preserve line breaks and the htmlspecialchars escape the caracters

    $mensaje = "&lt;Msg&gt;





                &lt;/Msg&gt;"; // This line contains the message format used in my particular webservice, it is neccesaey to replace the characters <,> with &lt; &gt;

    $request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>

      <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">


          <Send xmlns=\"<sendOperationURL>\">





$headers = [

                        "Method: POST", 

"Authorization: <auth header if neccesary>", // Depending on the web service the auth could be managed different

"Content-Type: text/xml; charset=utf-8",

"Host: <host name>",

                        "SOAPAction: <sendOperationURL>/<operation action>"


     $ch = curl_init($location);

     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

     curl_setopt($ch, CURLOPT_POST, true);

     curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

     curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

// I get some errors with SSL so I added the following two lines

     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);


     $response = curl_exec($ch);

So I manually send the mail using culr.