Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending emails from PHPMailer using proxies IP addresses

I need to send emails from PHPMailer using proxies IP addresses, I know that to do so, I need to use the fsockopen function so I can connect to the SMTP account, I also know that if I have to connect to the proxy I have to use the fsockopen function again. But using it fsockopen inside another fsockopen is not doable.

I have transparent proxy and require no authentication. I need to send this to a distant SMTP server of an external Email Service Provider.

The code I have tried :

<?php

    //SMTP params
    $server      = 'smtp.espdomain.com';
    $server_port = '25';
    $username = 'smtp_login';
    $password = 'smtp_pass';

    //Proxy
    $proxy      = '1.1.1.1';
    $proxy_port = 1111;

    //Open connection
    $socket = fsockopen($proxy, $proxy_port);

    //Send command to proxy
    fputs($socket, "CONNECT $server:$server_port HTTP/1.0\r\nHost: $proxy\r\n\r\n");
    fgets($socket, 334);

    //SMTP authorization  
    fputs($socket, "AUTH LOGIN\r\n");
    fgets($socket, 334);

    fputs($socket, base64_encode($username)."\r\n");
    fgets($socket, 334);

    fputs($socket, base64_encode($password)."\r\n");
    $output = fgets($socket, 235);

    fputs($socket, "HELO $server \r\n"); 
    $output = fgets($socket, 515);

?>

And it's not working I'm not sure why?

Could socat commands help in this situation or is there any solution or alternative solution to achieve that?

like image 987
Zakaria Acharki Avatar asked Mar 21 '16 17:03

Zakaria Acharki


People also ask

How do I send an email with a proxy server?

Using a proxy server, you can hide your original IP address and send mail without any risk to be detected. To do it, open “Settings” / “Common settings” / “Proxy”. Select the proxy server type (Socks 4, Socks 4A or Socks 5) and enter the server address there. Servers requiring authentication are also supported.

Why it is advantages to use PHPMailer for sending and receiving email?

PHPMailer can use a non-local mail server (SMTP) if you have authentication. Further advantages include: It can print various kinds of error messages in more than 40 languages when it fails to send an email. It has integrated SMTP protocol support and authentication over SSL and TLS.

How many emails can I send with PHPMailer?

PHPMailer does not set any limits, nor does the mail() function, it's only ISPs like GoDaddy that do. However, they do so by blocking access to normal SMTP ports, and/or redirecting SMTP connections to their own servers ( *. secureserver. * ).

Does PHPMailer use Sendmail?

PHPMailer is the classic email sending library for PHP. It supports several ways of sending email messages such as mail(), Sendmail, qmail, and direct dispatch to SMTP servers.


1 Answers

I finally found the solution using socat, Kindly follow these steps :

  1. First of all, you'll need to install socat on the server, you can do that simply using the command below :

    yum install socat
    
  2. Then run the following socat command that will bind PROXY_IP:PORT with HOST_ESP:PORT :

    socat TCP4-LISTEN:proxy_port,bind=proxy_IP,fork,su=nobody TCP4:host:port,bind=proxy_IP
    
  3. Then instead of making a send to the ESP through HOST_ESP:PORT you could just make it using PROXY_IP:PORT and socat will do the redirection automatically towards HOST_ESP:PORT using the output of PROXY_IP:PORT.

Hope this helps.

like image 160
Zakaria Acharki Avatar answered Sep 26 '22 09:09

Zakaria Acharki