cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

SMTP with TSL

From: Eric & Sherrell <svsarana_at_yahoo.com>
Date: Mon, 31 Oct 2011 06:52:06 -0700 (PDT)

Hi everyone,

I've been trying to use cURL with a tsl connection to an smtp server.  I've found the following problems:

1.  PHP curl with telnet and tsl can't connect.  Anyone know how to do this?
2.  There seems to be no SMTP support with the php libraries.  However I saw this example for libcurl:  http://curl.haxx.se/libcurl/c/smtp-tls.html.  Does this mean it might be coming?

Hacked Solution:
Using curl with an https connection I was able to find a hack that allowed me to send out simple SMTP messages by putting the entire smtp command strings and message into the customrequest field setting when connecting to the server.  Example snipit:

        curl_setopt($this->curl_handle, CURLOPT_URL, "https://$this->host:$this->port";);
        curl_setopt($this->curl_handle, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($this->curl_handle, CURLOPT_SSL_VERIFYHOST, true);
        curl_setopt($this->curl_handle, CURLOPT_CAINFO, "cacert.pem"); // local root CA copy
        curl_setopt($this->curl_handle, CURLOPT_CAPATH, "./");
        curl_setopt($this->curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($this->curl_handle, CURLOPT_HTTPHEADER, "");

        $out = "AUTH LOGIN\r\n";
        $out .= base64_encode($this->user) . "\r\n";
        $out .= base64_encode($this->password) . "\r\n";
        $out .= "MAIL FROM: <$from>\r\n";
        $out .= "RCPT TO: <$to>\r\n";
        $out .= "DATA\r\n";
        $out .= "To: $to\r\n";
        $out .="From: $from\r\n";
        $out .="Subject:  $subject\r\n\r\n";
        $out .=$message;
        $out .="\r\n.\r\n";
        $out .="QUIT\r\n";

        curl_setopt($this->curl_handle, CURLOPT_CUSTOMREQUEST, $out . "\r\n");
        curl_exec($this->curl_handle);

Since this is using the HTTP/HTTPS protocol, curl appends / http 1.0\nAllow */*\n to the end of the customrequest, but this gets ignored by the SMTP server after the QUIT is encountered.  A more detailed discussion can be found here http://forums.devnetwork.net/viewtopic.php?f=1&t=132442&p=663872#p663872

If you have any more stable ideas or solutions, I would love to hear them.

Regards,
Eric

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2011-10-31