Ver Mensaje Individual
  #2 (permalink)  
Antiguo 19/08/2010, 23:19
fabayan
 
Fecha de Ingreso: septiembre-2009
Mensajes: 87
Antigüedad: 14 años, 7 meses
Puntos: 1
Respuesta: Mails desde localhost con gmail

Calculo que no lo van a necesitar a menudo: pero estoy seguro que a algun otro trastornado que como yo se empeñe en enviar mails desde localhost con el SMTP de gmail o google apps le va a servir. El problema era el siguiente: resulta que google ha cambiado su protocolo de seguridad para autentificar su ingreso al smtp. De modo, pues, que salvo que se haga por la clase phpmailer modificada para usar el ssl de google, cualquier intento de salir con los correos desde la funcion de correo php que deriva a sendmail se volvia imposible. Asi, pues, que para que tu server apache (solo o el que instala wamp o xammp) mande correos desde localhost en Win lo que debes hacer es lo siguiente:

1 - Si tu server no trae fake sendmail de Byron Jones, lo bajas de aquí

http://www.glob.com.au/sendmail/sendmail.zip

2 - Copias los archivos en un directorio que llamas, p.ej, sendmail dentro de la carpeta de wamp o xammp.

3 - Como Gmail o google apps utilizan TLS/SSL, tambien bajas el siguiente archivo:

http://glob.com.au/sendmail/sendmail-SSL.zip

Y los colocas en la misma carpeta anterior. Es importante que esten las dll

4 - Abres el archivo php.ini de la versión de php que efectivamente esté corriendo en tu servidor. En Wamp o Xammp lo más practico es ir al menu php y alli podemos abrir el php.ini.

5 - Una vez que tienes abierto el php.ini buscas el apartado "mail function". Cuando termines de configurarlo te tiene que quedar algo asi:

Código:
[mail function]
; For Win32 only.
;SMTP = smtp.mailhost.tld
;smtp_port = 25

; For Win32 only.
sendmail_from = [email protected]

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path =  "c:\wamp\sendmail\sendmail.exe -t"
Donde "c:\wamp\sendmail\sendmail.exe -t" es el directorio donde bajaste todo lo anterior. Ten en cuenta esto si usas Xammp u otro server para apuntar al directorio correcto.

Asimismo, dentro de php.ini verificas que la extensión extension=php_openssl.dll esté habilitada. Si la ves asi: ;extension=php_openssl.dll, le quitas el punto y coma y con eso la habilitas.


6 - Abres ahora el archivo sendmail.ini que donde bajaste todo, este archivo te tiene que quedar mas o menos asi:

Código:
; configuration for fake sendmail

; if this file doesn't exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail

[sendmail]

; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory.  (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.

smtp_server=localhost

; smtp port (normally 25)

smtp_port=25

; SMTPS (SSL) support
;  auto = use SSL for port 465, otherwise try to use TLS
;   ssl  = alway use SSL
;   tls  = always use TLS
;   none = never try to use SSL

smtp_ssl=auto

; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify

default_domain=gmail.com

; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging

error_logfile=error.log

; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging

;debug_logfile=debug.log

; if your smtp server requires authentication, modify the following two lines

[email protected]
auth_password=xxxxxx

; if your smtp server uses pop3 before smtp authentication, modify the 
; following three lines.  do not enable unless it is required.

;pop3_server=
;pop3_username=
;pop3_password=

; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify 
; the "From: " header of the message content

[email protected]

; force the sender to always be the following email address
; this will only affect the "RCTP TO" command, it won't modify 
; the "To: " header of the message content

force_recipient=

; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting.  you can manually set the ehlo/helo name if required

; hostname=
7 - Ya queda poco, ánimo. Ahora, debido a la modificación que ha hecho google, lo que tienes que hacer es bajar un soft llamado stunnel, que es el encargado de hacer de puente entre el sendmail y smtp de google proporcionandole los datos que este ultimo requiere en cuanto a la seguridad. Lo bajas desde aquí:

http://www.stunnel.org/download/

Lo instalas pero no lo corres todavía.

En cambio, abres el archivo stunnel.conf y lo modificas para que tome los envios que sendmail hace y te quede así:

Código:
; Sample stunnel configuration file by Michal Trojnara 2002-2006
; Some options used here may not be adequate for your particular configuration

; Certificate/key is needed in server mode and optional in client mode
; The default certificate is provided only for testing and should not
; be used in a production environment
cert = stunnel.pem
;key = stunnel.pem

; Some performance tunings
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1

; Workaround for Eudora bug
;options = DONT_INSERT_EMPTY_FRAGMENTS

; Authentication stuff
;verify = 2
; Don't forget to c_rehash CApath
;CApath = certs
; It's often easier to use CAfile
;CAfile = certs.pem
; Don't forget to c_rehash CRLpath
;CRLpath = crls
; Alternatively you can use CRLfile
;CRLfile = crls.pem

; Some debugging stuff useful for troubleshooting
debug = 7
output = stunnel.log

; Use it for client mode
client = yes

; Service-level configuration

[pop3s]
accept  = 995
connect = 110

[imaps]
accept  = 993
connect = 143

[ssmtp]
accept  = 465
connect = 25

;[https]
;accept  = 443
;connect = 80
;TIMEOUTclose = 0

[smtpg] 
accept = 127.0.0.1:25 
connect = smtp.gmail.com:465

; vim:ft=dosini

8 - Echo esto, puedes correr stunnel.

9 - Por último: reinicias wamp o xammp.

10 - Vualá.... puedes mandar mensajes desde localhost con tu cuenta de gmail y correr scripts tanto en joomla como en php solo y evitas todas las soluciones que te mandan los mensajes a la carpeta de spam. Recuerda, sin embargo, que estos envios están limitados a 200/500 por día. No es para listas de correos muy grandes, spam o sitios con mucho trafico de emails.

Espero que sirva.

PS: ojo con hacer la primera prueba con el firewall o el antivirus activos. Haganlo sin ellos para eliminar el riesgo de bloqueos, luego lo encienden nuevamente.

Cualquier duda pregunten sin problemas

Última edición por fabayan; 19/08/2010 a las 23:26