Error sc_mail_send

Hello,
When using the sc_mail_send macro on my local server, everything works without complications, but I export the project and use it in the production environment it throws an error and does not send, which could be happening, the error in theory is by port, I am using gmail smtp, when using port 465 everything works fine, but only on my local server, not on the production server, will it be a permission problem? I don’t think the port is a problem because it works in scriptcase in a test environment, but in deployed it doesn’t work.

My test environment is windows from scriptcase, the production environment is a hosting with linux 64bits

the generated error is:

Fatal error : Uncaught Swift_TransportException: Connection could not be established with host smtp.gmail.com [ #0] in /home/grupobot/public_html/inadimplencia/_lib/prod/third/swift/classes/Swift/Transport/StreamBuffer.php:269 Stack trace: #0 /home/grupobot/public_html/inadimplencia/_lib/prod/third/swift/classes/Swift/Transport/StreamBuffer.php(62): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 /home/grupobot/public_html/inadimplencia/_lib/prod/third/swift/classes/Swift/Transport/AbstractSmtpTransport.php(113): Swift_Transport_StreamBuffer->initialize(Array) #2 /home/grupobot/public_html/inadimplencia/ lib/prod/third/swift/classes/Swift/Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() #3 /home/grupobot/public_html/inadimplencia/form_sac/form_sac_apl.php(4237): Swift_Mailer->send(Object(Swift_Message), Array) #4 /home/grupobot/public_html/inadimplencia/form_sac/form_sac_apl.php(1307): form_sac_apl->nm_acessa_banco() #5 /home/grupobot/public_html/inadimplencia/form_sac/index.php(2251): form_sac in /home/grupobot/public_html/inadimplencia/_lib/prod/third/swift/classes/Swift/Transport/StreamBuffer.php on line 269

Well, the message sais that it cannot connect to the host. So there is an issue with your ip, the smtp values like ssl, tls etc. or the port that you are using. The message is quite clear actually. GMail is refusing your connection so there must be something wrong in the settings you provide. Try

Hello,
Thanks for the prompt response.

taking into account the recommendations:

  • port problem is not, the same configuration works on my local server and I have tested all port and security conditions.
  • Folder permission problem is not, because I have changed permissions.
  • The only point that remained was that comment from the IP.

Apparently definitive gmail prevented the sending from the web server, so I created an email account from the same web server, I did tests and it comes out without problems, it is not the definitive solution, I must find out what happens between gmail and my hosting, but it works .

so resolved the issue, thank you very much

I was getting SMTP connection errors too - trying to connect to SparkPost SMTP. Google and other SMTP services require TLS 1.2 to establish a secure connection. SwiftMailer still has settings for TLS 1.0 in the most recent distribution included with SC 9.4.

This is the only thing that fixed it for me:

After exporting SC common files and establishing your apps on the Linux server, go to -

path/to/_lib/prod/third/swift/classes/Swift/Transport/StreamBuffer.php

Find: STREAM_CRYPTO_METHOD_TLS_CLIENT);
Replace with: STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT);

This fixed my SMTP connection issues when the Port, credentials and everything else was correct but the connection would not work - error messages.

Note that every time you update your production environment with new common libraries, you’ll have to make that edit, until SwiftMailer/SC updates that one file.

Good luck - hope it works for you.

2 Likes

Cheers rjjacob,

Thank you very much for the answer, I did the tests in the indicated code, but it still doesn’t work, it seems to be some server block in relation to gmail.

As I said before, temporarily and without being the final solution, I am sending emails from an account on the same hosting.

very thankful.

same problem here:

ERROR:

Fatal error: Uncaught Swift_TransportException: Connection to tcp://198.46.82.38:465 Timed Out in C:\Program Files\NetMake\v92\wwwroot\scriptcase\prod\third\swift\classes\Swift\Transport\AbstractSmtpTransport.php:404 Stack trace: #0 C:\Program Files\NetMake\v92\wwwroot\scriptcase\prod\third\swift\classes\Swift\Transport\AbstractSmtpTransport.php(289): Swift_Transport_AbstractSmtpTransport->_getFullResponse(0) #1 C:\Program Files\NetMake\v92\wwwroot\scriptcase\prod\third\swift\classes\Swift\Transport\AbstractSmtpTransport.php(117): Swift_Transport_AbstractSmtpTransport->readGreeting() #2 C:\Program Files\NetMake\v92\wwwroot\scriptcase\prod\third\swift\classes\Swift\Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start() #3 C:\Program Files\NetMake\v92\wwwroot\scriptcase\app\TECREP5\s_form_add_users\s_form_add_users_apl.php(4536): Swift_Mailer->send(Object(Swift_Message), Array) #4 C:\Program Files\NetMake\v92\wwwroot\scriptcase\app\TECREP5\s_form_add_users\s_form_add_users_apl.php(3870): s_form_add_users_apl->send in C:\Program Files\NetMake\v92\wwwroot\scriptcase\prod\third\swift\classes\Swift\Transport\AbstractSmtpTransport.php on line 404

Any body has a real fix to this issue, i guess mine is different since i have comment out the mailing option in my application for now i guess, anything i put in the “email” field should work, i presume…