0

Whenever I run a simple send email function using Email::Send::Gmail I get this error:

[Mon Jan 28 11:37:57 2013] [error] [client 31.171.245.] Error sending email: Email::Send::Gmail: error connecting to server smtp.gmail.com at /usr/local/share/perl5/Email/Send.pm line 252, referer: http://**.cgi

However, exact same code is working when run from command line. And smtp.gmail.com is available when telneting from command line. It this because of the persistence or am I missing something?

Bogdan
  • 118
  • 1
  • 3
  • 11
  • Perhaps GMail has specifically disallowed sending emails via script? –  Jan 28 '13 at 11:23
  • Also, perhaps this thread will help: http://www.perlmonks.org/?node_id=719444 –  Jan 28 '13 at 11:28
  • Well it is working from the command line, I can't see any reason why the same code shouldn't work as CGI – Bogdan Jan 28 '13 at 13:00

2 Answers2

0

Alrgiht, I got it. Seems selinux on CentOS was blocking outside connections from httpd, thus the script was not connecting.

You need to enter this

setsebool -P httpd_can_network_connect=1

In order to connect.

Bogdan
  • 118
  • 1
  • 3
  • 11
-1

Try (in your cgi script) doing this:

use Net::SMTP::SSL;
Net::SMTP::SSL->new( 'smtp.gmail.com', Port => 465, Debug => 1 );

and see if the debugging information tells you anything helpful.

Is it possible that your cgi script is using a different perl, with different modules installed?

ysth
  • 96,171
  • 6
  • 121
  • 214
  • This snippet is working like that and it should be using the same perl, otherwise there'd be an entry in the error log about the missing module, i've seen such before. I even exported the sending part to an outside script and tried sending by supplying parameters, still same error. – Bogdan Jan 28 '13 at 12:26
  • 1
    that snippet doesn't actually check for success, but the error message you are getting from Email::Send::Gmail indicates that new call is failing. what *does* the debug info look like, and is it any different run from the command line? – ysth Jan 28 '13 at 13:52
  • Thanks, might by a silly question, but how do I output the debug onto the CGI i.e. being displayed in the browser, or should i redirect stdout to stderr so I can read it in the error log? – Bogdan Jan 29 '13 at 11:09