Using Gmail or External SMTP Server [SSL] and port 587 to send out e-mails for Windows
Step 1 - Download and Configure Sendmail
The first step is to download Fake Sendmail created by Byron Jones. I have provided a copy which already has SSL supported added in and configured to work with Gmail which can be downloaded by clicking here.
You will need to extract it somewhere on your server. It's recommended that you choose somewhere sensible because once it is set up, you will need to reconfigure PHP if you change the path, so don't bother with your Desktop. If you have locked down Apache and PHP with a seperate locked down user account, that user account will need access to read and run applications in the folder where you stored Sendmail. For the purpose of this guide, I have stored it in my Web folder; C:\Web\PHP\sendmail\
![]()
Extract sendmail.zip to your created sendmail folder.
Once extracted, open sendmail.ini in Notepad. You will need to customize this configuration to your own. The words in red must be changed and configured to your settings.
; 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=smtp.gmail.com ; smtp port (normally 25) smtp_port=587 ; 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=enteryourdomain.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 auth_username=Gmail username auth_password=Gmail password ; if your smtp server uses pop3 before smtp authentication, modify the ; following three lines pop3_server= pop3_username= pop3_password= ; to force the sender to always be the following email address, uncomment and ; populate with a valid email address. this will only affect the "MAIL FROM" ; command, it won't modify the "From: " header of the message content force_sender=webmaster@enteryourdomain.com ; 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=
Once you have configured this, save your sendmail.ini and Sendmail is configured.
Step 2 - Configuring PHP to use Sendmail
You will need to open your PHP configuration (php.ini), then need to look for the [mail function] section. Once you have found it, look for the line which asks for sendmail_path. You may notice it says for Unix only, but ignore this.
; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). sendmail_path = "C:\Web\PHP\sendmail\sendmail.exe -t"
In this case, I am storing "sendmail.exe" in C:\Web\PHP\sendmail. If you are storing sendmail.exe elsewhere, be sure to change it here. You also need to add the argument -t for it to work.
Also ensure all other options under [mail function] is commented out using ; so that the sendmail path is the only option uncommented.
Your [mail function] should now look something like this:
[mail function] ; For Win32 only. ;SMTP = localhost ;smtp_port = 25 ; For Win32 only. ;sendmail_from = me@example.com ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). sendmail_path = "C:\Web\PHP\sendmail\sendmail.exe -t" ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(), even in safe mode. ;mail.force_extra_parameters =
You have configured PHP to use your sendmail which should in turn send the e-mail via your Gmail account and port 587!
Step 3 - Test Mail Server
In this case, I am using Drupal's contact form and with my No-IP to test out my e-mail.
![]()
Sending an e-mail via Drupal contact form, with my dynamic IP address.
If you have configured your G-mail account as the SMTP correctly, you should be able to send out the message.
![]()
For confirmation, login to your e-mail account which you have sent the test e-mail minutes ago. You should be able to receive it if your 587 port isn't blocked. If you didn't receive it after for quite some time, check your firewall or router's port and make sure port 587 is forwarded/opened.
Congratulations! You are now using SMTP Gmail and port 587 to send out e-mails. Facing any problem configuring? Drop me an e-mail or post a comment below and I will do my best to help out.
UPDATES (13 APRIL 2010)
As of March 14th, Google phased out SSLv2. Since, Byron Jones' fake sendmail application depended on it, all of us who were using it found out that it no longer worked.
Here are step-by-step instructions to fix it. You need stunnel.
Download and Install: http://www.stunnel.org/download/stunnel/win32/stunnel-4.33-installer.exe
In start menu, go to stunnel folder and click on 'Edit stunnel.conf'
Copy the following into stunnel.conf and save.
cert = stunnel.pem
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
debug = 7
output = stunnel.log
client = yes
[smtpg]
accept = 127.0.0.1:25
connect = smtp.gmail.com:465
Run stunnel
Edit sendmail.ini and change to the following:
smtp_server=localhost
smtp_port=25
It should be working fine now :)
- 5744 reads
Hi, great tutorial, I have
Hi,
great tutorial, I have been playing around the fake sendmail + gmail smtp server.
I want to know if it is possible to change the sender email add, because here everytime it is sending out email using the gmail username like "myname@gmail.com". Is it possible to change it to something like "XXX@YYY.com". Or any freeware that can do that? (I don't have a mail server though)
Hi there Munna, Sorry for
Hi there Munna,
Sorry for getting back to you quite late on this.
I'm not sure whether other mail services like Hotmail and Yahoo does that.
Anyhow, there are several freeware mail servers that you can install on your server. Are you setting up your own server at home?
Hi, I am trying to send mail
Hi,
I am trying to send mail through stunnel. I am able to send mail through gmail and yahoo but it doesn't work for Hotmail.
This is the log I got
2011.01.24 14:15:45 LOG7[10041:806741216]: Service ssmtp started
2011.01.24 14:15:45 LOG7[10041:806741216]: FD=13 in non-blocking mode
2011.01.24 14:15:45 LOG7[10041:806741216]: Option TCP_NODELAY set on local socket
2011.01.24 14:15:45 LOG7[10041:806741216]: Waiting for a libwrap process
2011.01.24 14:15:45 LOG7[10041:806741216]: Acquired libwrap process #0
2011.01.24 14:15:45 LOG7[10041:806741216]: Releasing libwrap process #0
2011.01.24 14:15:45 LOG7[10041:806741216]: Released libwrap process #0
2011.01.24 14:15:45 LOG7[10041:806741216]: Service ssmtp permitted by libwrap from 127.0.0.1:54998
2011.01.24 14:15:45 LOG5[10041:806741216]: Service ssmtp accepted connection from 127.0.0.1:54998
2011.01.24 14:15:45 LOG7[10041:806741216]: FD=14 in non-blocking mode
2011.01.24 14:15:45 LOG6[10041:806741216]: connect_blocking: connecting 65.55.162.200:587
2011.01.24 14:15:45 LOG7[10041:806741216]: connect_blocking: s_poll_wait 65.55.162.200:587: waiting 10 seconds
2011.01.24 14:15:45 LOG5[10041:806741216]: connect_blocking: connected 65.55.162.200:587
2011.01.24 14:15:45 LOG5[10041:806741216]: Service ssmtp connected remote server from 13.13.0.140:43822
2011.01.24 14:15:45 LOG7[10041:806741216]: Remote FD=14 initialized
2011.01.24 14:15:45 LOG7[10041:806741216]: Option TCP_NODELAY set on remote socket
2011.01.24 14:15:45 LOG5[10041:806741216]: Negotiations for smtp (client side) started
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 220 BLU0-SMTP157.blu0.hotmail.com Microsoft ESMTP MAIL Service, Version:
6.0.3790.4675 ready at Mon, 24 Jan 2011 11:15:34 -0800
2011.01.24 14:15:45 LOG7[10041:806741216]: -> 220 BLU0-SMTP157.blu0.hotmail.com Microsoft ESMTP MAIL Service, Version:
6.0.3790.4675 ready at Mon, 24 Jan 2011 11:15:34 -0800
2011.01.24 14:15:45 LOG7[10041:806741216]: -> EHLO localhost
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-BLU0-SMTP157.blu0.hotmail.com Hello [13.13.0.140]
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-TURN
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-SIZE 41943040
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-ETRN
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-PIPELINING
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-DSN
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-ENHANCEDSTATUSCODES
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-8bitmime
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-BINARYMIME
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-CHUNKING
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-VRFY
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-TLS
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250-STARTTLS
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 250 OK
2011.01.24 14:15:45 LOG7[10041:806741216]: -> STARTTLS
2011.01.24 14:15:45 LOG7[10041:806741216]: <- 220 2.0.0 SMTP server ready
2011.01.24 14:15:45 LOG5[10041:806741216]: Protocol negotiations succeeded
2011.01.24 14:15:45 LOG7[10041:806741216]: SSL state (connect): before/connect initialization
2011.01.24 14:15:45 LOG7[10041:806741216]: SSL state (connect): SSLv3 write client hello A
2011.01.24 14:15:45 LOG7[10041:806741216]: SSL state (connect): SSLv3 read server hello A
2011.01.24 14:15:45 LOG7[10041:806741216]: SSL state (connect): SSLv3 read server certificate A
2011.01.24 14:15:45 LOG7[10041:806741216]: SSL state (connect): SSLv3 read server done A
2011.01.24 14:15:45 LOG7[10041:806741216]: SSL state (connect): SSLv3 write client key exchange A
2011.01.24 14:15:45 LOG7[10041:806741216]: SSL state (connect): SSLv3 write change cipher spec A
2011.01.24 14:15:45 LOG7[10041:806741216]: SSL state (connect): SSLv3 write finished A
2011.01.24 14:15:45 LOG7[10041:806741216]: SSL state (connect): SSLv3 flush data
2011.01.24 14:15:45 LOG7[10041:806741216]: SSL state (connect): SSLv3 read finished A
2011.01.24 14:15:45 LOG7[10041:806741216]: 1 items in the session cache
2011.01.24 14:15:45 LOG7[10041:806741216]: 1 client connects (SSL_connect())
2011.01.24 14:15:45 LOG7[10041:806741216]: 1 client connects that finished
2011.01.24 14:15:45 LOG7[10041:806741216]: 0 client renegotiations requested
2011.01.24 14:15:45 LOG7[10041:806741216]: 0 server connects (SSL_accept())
2011.01.24 14:15:45 LOG7[10041:806741216]: 0 server connects that finished
2011.01.24 14:15:45 LOG7[10041:806741216]: 0 server renegotiations requested
2011.01.24 14:15:45 LOG7[10041:806741216]: 0 session cache hits
2011.01.24 14:15:45 LOG7[10041:806741216]: 0 external session cache hits
2011.01.24 14:15:45 LOG7[10041:806741216]: 0 session cache misses
2011.01.24 14:15:45 LOG7[10041:806741216]: 0 session cache timeouts
2011.01.24 14:15:45 LOG6[10041:806741216]: SSL connected: new session negotiated
2011.01.24 14:15:45 LOG6[10041:806741216]: Negotiated ciphers: DES-CBC3-SHA SSLv3 Kx=RSA Au=RSA Enc=3DES(168) Mac=SHA1
2011.01.24 14:15:45 LOG7[10041:806741216]: SSL alert (write): fatal: handshake failure
2011.01.24 14:15:45 LOG3[10041:806741216]: SSL_read: 1408F10B: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number
2011.01.24 14:15:45 LOG5[10041:806741216]: Connection reset: 60 bytes sent to SSL, 246 bytes sent to socket
2011.01.24 14:15:45 LOG7[10041:806741216]: Service ssmtp finished (0 left)
I am using TLSv1 as SSl version.
Please tell me where is the fault.
Thanks & regards,
Anoop.
Post new comment