Difference between revisions of "5.3-Nano: msmtp"

From The Uniform Server Wiki
Jump to navigation Jump to search
(New page: {{Nav 5.3-Nano}} '''Uniform Server and Msmtp an SMTP client''' It’s been a long time since I looked at SMTP clients. Generally most use the Windows registry however for portability that...)
 
(Minor grammar and spelling changes)
 
Line 1: Line 1:
 
{{Nav 5.3-Nano}}
 
{{Nav 5.3-Nano}}
'''Uniform Server and Msmtp an SMTP client'''
+
'''Uniform Server and Msmtp, an SMTP client'''
  
It’s been a long time since I looked at SMTP clients. Generally most use the Windows registry however for portability that’s a no go. I finally narrowed it down to '''msmtp''' its flexible, relative easy to set-up more importantly its portable.
+
It’s been a long time since I looked at SMTP clients. Generally most use the Windows registry, but for portability that’s a no go. I finally narrowed it down to '''msmtp'''. It's flexible, relative easy to set-up, and more importantly it's portable.
  
The above can be configured to use your ISP’s SMTP server however that again restricts portability. The answer is to create a free account at Google Mail ('''gmail''') and configure msmtp to use that.
+
While msmtp can be configured to use your ISP’s SMTP server, that again restricts portability. The answer is to create a free account at Google Mail ('''gmail''') or '''Hotmail''' and configure msmtp to use that.
  
This combination allows any PHP scripts to send e-mail to your gmail account transparently. MSMTP has been integrated into Uniform Server all you need to do is configure the account as explained below.  
+
This combination allows any PHP scripts to send e-mail to your gmail account transparently. MSMTP has been integrated into Uniform Server. All you need to do is configure the account as explained below.  
  
 
== Background ==
 
== Background ==
SMTP (simple mail transport protocol) was originally designed to be an open relay where an SMTP server would accept any e-mail for forwarding. This quickly became abused by spammers in retaliation ISP’s restricted open relaying. This means you cannot use the PHP function to directly send e-mail to a user. You either require your own mail server with all the complication that is associated with it or use your ISP’s SMTP server. In either situation you are restricted to a local server on a dedicated line.
+
SMTP (simple mail transport protocol) was originally designed to be an open relay where an SMTP server would accept any e-mail for forwarding. This quickly became abused by spammers. In retaliation, ISP’s restricted open relaying. This means you cannot use the PHP function to directly send e-mail to a user. You either require your own mail server with all the complication that is associated with it, or you use your ISP’s SMTP server. In either situation you are restricted to a local server on a dedicated line.
  
Free e-mail accounts such as Google Mail remove these chains by allowing you to relay through their servers. However you must login to their servers before this privilege is granted that’s the price you pay.
+
Free e-mail accounts such as Google Mail remove these chains by allowing you to relay through their servers. However you must login to their servers before this privilege is granted.  That’s the price you pay.
  
That said add the above solution to DtDNS and you have a real portable server.  
+
That said, add the above solution to DtDNS and you have a real portable server.  
  
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''
Line 19: Line 19:
 
PHP uses the default account as set in configuration file UniServer\msmtp\'''msmtprc.ini'''
 
PHP uses the default account as set in configuration file UniServer\msmtp\'''msmtprc.ini'''
  
Before running any PHP scripts that send mail at least '''one account''' in this file must be configured and set as default.
+
Before running any PHP scripts that send mail, at least '''one account''' in this file must be configured and set as default.
  
The file contains three-example configurations that will suit most requirements.  
+
The file contains three example configurations that will suit most requirements.  
  
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''
 
=== MyISP ===
 
=== MyISP ===
The first account, MyISP replaces the basic sendmail settings that would have been set in the php.ini file.
+
The first account, MyISP, replaces the basic sendmail settings that would have been set in the php.ini file.
  
 
It assumes your Internet service provider does not require you to authenticate. Hence all that is required is your ISP’s smtp server name and your email address.
 
It assumes your Internet service provider does not require you to authenticate. Hence all that is required is your ISP’s smtp server name and your email address.
Line 48: Line 48:
 
'''''Note'':''' Other accounts are ignored. PHP will use this account to send emails and your ISP will relay them to the appropriate address.
 
'''''Note'':''' Other accounts are ignored. PHP will use this account to send emails and your ISP will relay them to the appropriate address.
  
I mentioned above this account is restrictive because it ties you to your service provider hence is not portable. However it has one advantage requires minimum of configuration.
+
I mentioned above that this account is restrictive because it ties you to your service provider, so it is not portable. However it has one advantage which is it requires a minimum of configuration.
  
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''
  
 
=== Hotmail ===
 
=== Hotmail ===
The second account, Hotmail is a free account that you need to create at the following address '''http//www.hotmail.com''' once signed up you will have an email address and password. These are required to configure your msmtp account.  
+
The second account, Hotmail, is a free account that you need to create at the following address '''http//www.hotmail.com''' once signed up you will have an email address and password. These are required to configure your msmtp account.  
 
{|
 
{|
 
|-
 
|-
Line 81: Line 81:
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''
 
=== Gmail ===
 
=== Gmail ===
The third account, Gmail is a free account that you need to create at the following address '''http://mail.google.com/''' once signed up you will have an email address and password. These are required to configure your msmtp account.  
+
The third account, Gmail, is a free account that you need to create at the following address '''http://mail.google.com/''' once signed up you will have an email address and password. These are required to configure your msmtp account.  
 
{|
 
{|
 
|-
 
|-
Line 111: Line 111:
  
 
=== General Note ===
 
=== General Note ===
I would recommend you sign-up to the above free accounts and try each in tern (change default) to determine which best suits your requirements. You can create any number of accounts however make sure the account name is unique.
+
I would recommend you sign-up to the above free accounts and try each in turn (by changing the default) to determine which best suits your requirements. You can create any number of accounts, however make sure the account name is unique.
  
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''
Line 186: Line 186:
  
 
== Integration ==
 
== Integration ==
You can skip this section however if you are interested in how msmtp integrates into Uniform Server’s architecture read on. This section is useful for users who wish to upgrade when a newer version of msmtp is released.
+
You can skip this section. However if you are interested in how msmtp integrates into Uniform Server’s architecture, read on. This section is useful for users who wish to upgrade when a newer version of msmtp is released.
  
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''
Line 196: Line 196:
 
* To folder: UniServer\'''msmtp'''
 
* To folder: UniServer\'''msmtp'''
  
If you are upgrading that’s all there is to do.
+
If you are upgrading, that’s all there is to do.
  
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''
 
=== How it is integrated ===
 
=== How it is integrated ===
There are three requirements for integration, inform PHP where to find the msmtp executable, inform msmtp where to find it’s configuration file. Finally inform msmtp where it’s log file is to be located.
+
There are three requirements for integration: inform PHP where to find the msmtp executable, inform msmtp where to find its configuration file, and finally inform msmtp where its log file is to be located.
  
The configuration file is located in folder UniServer\'''msmtp''' and named '''msmtprc.ini''' (could have been any other appropriate name) This configuration file contains a path to the log file it is specified as an absolute for example:
+
The configuration file is located in folder UniServer\'''msmtp''' and named '''msmtprc.ini''' (could have been any other appropriate name) This configuration file contains a path to the log file, specified as an absolute path. For example:
  
 
logfile "C:/some_folder/UniServer/msmtp/sendmail.log"
 
logfile "C:/some_folder/UniServer/msmtp/sendmail.log"
  
'''''Note'':''' When servers are moved this path is automatically updated.
+
'''''Note'':''' When servers are moved, this path is automatically updated.
  
A single line placed in php.ini configuration file caters for the first two requirements. Line has the following format:
+
A single line placed in php.ini configuration file caters to the first two requirements. Line has the following format:
  
 
sendmail_path = "C:/some_folder/UniServer/msmtp/msmtp.exe --file=C:/ some_folder/UniServer/msmtp/msmtprc.ini  -t"
 
sendmail_path = "C:/some_folder/UniServer/msmtp/msmtp.exe --file=C:/ some_folder/UniServer/msmtp/msmtprc.ini  -t"
 
    
 
    
'''''Note 1'':''' Absolute paths with forward slashes are used. The first part instructs PHP where to find the msmtp executable second part instructs msmtp where to find its configuration file.
+
'''''Note 1'':''' Absolute paths with forward slashes are used. The first part instructs PHP where to find the msmtp executable, and the second part instructs msmtp where to find its configuration file.
  
'''''Note 2'':''' When servers are moved line sendmail_path is automatically updated reflecting the new paths.   
+
'''''Note 2'':''' When servers are moved, line sendmail_path is automatically updated reflecting the new paths.   
  
 
There are three php.ini files (php.ini, php.ini_delvelopment_nano and php.ini_production_nano) that require modification, parts of the sendmail section are commented out and the above line added as shown below:  
 
There are three php.ini files (php.ini, php.ini_delvelopment_nano and php.ini_production_nano) that require modification, parts of the sendmail section are commented out and the above line added as shown below:  
Line 245: Line 245:
 
</pre>
 
</pre>
 
|}
 
|}
'''''Note'':''' File $usf_msmtp is defined in UniServer\unicon\main\includes\'''config.inc.php'''. A user may delete msmtp and use an alternative hence files existence is check first, this prevents error messages.
+
'''''Note'':''' File $usf_msmtp is defined in UniServer\unicon\main\includes\'''config.inc.php'''. A user may delete msmtp and use an alternative. So the file's existence is check first; this prevents error messages.
  
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''
  
 
=== General note ===
 
=== General note ===
At first sight msmtp.exe looks large at 2.13 MB however it is self contained and compares favourably with alternatives such as fake send mail sendmail.exe 828 KB requires, libeay32.dll 1.06 MB and ssleay32.dll 208 KB  
+
At first sight, msmtp.exe looks large at 2.13 MB, however it is self contained and compares favourably with alternatives such as fake sendmail.  sendmail.exe (828 KB) requires libeay32.dll (1.06 MB) and ssleay32.dll (208 KB) (=2.10 MB).
  
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''
  
 
== Summary ==
 
== Summary ==
For a home web server or small business server the above is a very good compromise.  
+
For a home web server or small business server, the above is a very good compromise.  
  
However for a portable server it is ideal, include this with DtDNS and you can have a portable server on-line within ten minutes with email capability.
+
However for a portable server it is ideal. Include this with DtDNS and you can have a portable server with email capability on-line within ten minutes.
  
 
'''''[[#top | Top]]'''''
 
'''''[[#top | Top]]'''''

Latest revision as of 23:18, 27 January 2010

 

Uniform Server and Msmtp, an SMTP client

It’s been a long time since I looked at SMTP clients. Generally most use the Windows registry, but for portability that’s a no go. I finally narrowed it down to msmtp. It's flexible, relative easy to set-up, and more importantly it's portable.

While msmtp can be configured to use your ISP’s SMTP server, that again restricts portability. The answer is to create a free account at Google Mail (gmail) or Hotmail and configure msmtp to use that.

This combination allows any PHP scripts to send e-mail to your gmail account transparently. MSMTP has been integrated into Uniform Server. All you need to do is configure the account as explained below.

Background

SMTP (simple mail transport protocol) was originally designed to be an open relay where an SMTP server would accept any e-mail for forwarding. This quickly became abused by spammers. In retaliation, ISP’s restricted open relaying. This means you cannot use the PHP function to directly send e-mail to a user. You either require your own mail server with all the complication that is associated with it, or you use your ISP’s SMTP server. In either situation you are restricted to a local server on a dedicated line.

Free e-mail accounts such as Google Mail remove these chains by allowing you to relay through their servers. However you must login to their servers before this privilege is granted. That’s the price you pay.

That said, add the above solution to DtDNS and you have a real portable server.

Top

Configuration

PHP uses the default account as set in configuration file UniServer\msmtp\msmtprc.ini

Before running any PHP scripts that send mail, at least one account in this file must be configured and set as default.

The file contains three example configurations that will suit most requirements.

Top

MyISP

The first account, MyISP, replaces the basic sendmail settings that would have been set in the php.ini file.

It assumes your Internet service provider does not require you to authenticate. Hence all that is required is your ISP’s smtp server name and your email address.

account MyISP
host smpt.tiscali.co.uk
from johm.doe@tiscali.co.uk
auth off
  • Substitute smpt.tiscali.co.uk with your ISP's smpt server (The one you used to set up your e-mail client e.g Outlook express.)
  • Substitute john.doe@tiscali.co.uk with your real email address

To make this account the default

Change line account default : Hotmail to account default : MyISP

Note: Other accounts are ignored. PHP will use this account to send emails and your ISP will relay them to the appropriate address.

I mentioned above that this account is restrictive because it ties you to your service provider, so it is not portable. However it has one advantage which is it requires a minimum of configuration.

Top

Hotmail

The second account, Hotmail, is a free account that you need to create at the following address http//www.hotmail.com once signed up you will have an email address and password. These are required to configure your msmtp account.

account Hotmail
tls on
tls_certcheck off
host smtp.live.com
from john.doe123@hotmail.co.uk
auth on
user john.doe123@hotmail.co.uk
password fred123
  • Substitute from john.doe123@hotmail.co.uk with your login email address

This account requires authentication hence your login details:

  • Substitute user john.doe123@hotmail.co.uk with your login email address
  • Substitute password fred123 with your login password

To make this account the default

Line account default : Hotmail remains unchanged

Note: Other accounts are ignored. PHP will use this account to send emails and Hotmail servers will relay them to the appropriate address.

Top

Gmail

The third account, Gmail, is a free account that you need to create at the following address http://mail.google.com/ once signed up you will have an email address and password. These are required to configure your msmtp account.

account Gmail
tls on
port 587
tls_certcheck off
host smtp.gmail.com
from john.doe777@gmail.com
auth on
user john.doe777@gmail.com
password fred999
  • Substitute from john.doe777@gmail.com with your login email address

This account requires authentication hence your login details:

  • Substitute user john.doe777@gmail.com with your login email address
  • Substitute password fred999 with your login password

To make this account the default

Change line account default : Hotmail to account default : Gmail

Note: Other accounts are ignored. PHP will use this account to send emails and Gmail servers will relay them to the appropriate address.

Top

General Note

I would recommend you sign-up to the above free accounts and try each in turn (by changing the default) to determine which best suits your requirements. You can create any number of accounts, however make sure the account name is unique.

Top

Test Scripts

Create the following scripts and save them to folder UniServer\www

mail.php

<html>
<head><title>PHP Mail Sender</title></head>
<body>
<?php

# Retrieve the form data
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];

# Check if a $_POST value exists
# If not use defaults
if (empty($_POST['email'])){
  $email = "xxx.xxxx@tiscali.co.uk";
}
if (empty($_POST['subject'])){
  $subject = "UniCenter test";
}
if (empty($_POST['message'])){
  $message = "A quick test from UniCenter";
}

# Sends mail and report success or failure
if (mail($email,$subject,$message)) {
  echo "<h4>Thank you for sending email</h4>";
} else {
  echo "<h4>Can't send email to $email</h4>";
}
?>
</body>
</html>

 ;

mail.html

<html>
<head><title>Mail sender</title></head>
<body>
<form action="mail.php" method="POST">
<b>Email</b><br>
<input type="text" name="email" size=40>
<p><b>Subject</b><br>
<input type="text" name="subject" size=40>
<p><b>Message</b><br>
<textarea cols=40 rows=10 name="message"></textarea>
<p><input type="submit" value=" Send ">
</form>
</body>
</html>

Test:

  • Set a default account in file msmtprc.ini
  • Re-start servers
  • Run mail.html type: http://localhost/mail.html into a browser
  • Send emails as appropriate
  • Use browser back button to return to mail form

Top

Integration

You can skip this section. However if you are interested in how msmtp integrates into Uniform Server’s architecture, read on. This section is useful for users who wish to upgrade when a newer version of msmtp is released.

Top

Upgrade

Download the latest version (currently msmtp-1.4.18-w32.zip) from http://sourceforge.net/projects/msmtp/files/

  • Unzip to any folder.
  • Copy file: msmtp-1.4.18-w32\msmtp-1.4.18-w32\msmtp.exe
  • To folder: UniServer\msmtp

If you are upgrading, that’s all there is to do.

Top

How it is integrated

There are three requirements for integration: inform PHP where to find the msmtp executable, inform msmtp where to find its configuration file, and finally inform msmtp where its log file is to be located.

The configuration file is located in folder UniServer\msmtp and named msmtprc.ini (could have been any other appropriate name) This configuration file contains a path to the log file, specified as an absolute path. For example:

logfile "C:/some_folder/UniServer/msmtp/sendmail.log"

Note: When servers are moved, this path is automatically updated.

A single line placed in php.ini configuration file caters to the first two requirements. Line has the following format:

sendmail_path = "C:/some_folder/UniServer/msmtp/msmtp.exe --file=C:/ some_folder/UniServer/msmtp/msmtprc.ini -t"

Note 1: Absolute paths with forward slashes are used. The first part instructs PHP where to find the msmtp executable, and the second part instructs msmtp where to find its configuration file.

Note 2: When servers are moved, line sendmail_path is automatically updated reflecting the new paths.

There are three php.ini files (php.ini, php.ini_delvelopment_nano and php.ini_production_nano) that require modification, parts of the sendmail section are commented out and the above line added as shown below:

[mail function]
; For Win32 only.
;SMTP = localhost
;smtp_port = 25

; For Win32 only.
;sendmail_from = me@localhost.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path = "/usr/bin/sendmail.exe -t"

sendmail_path = "C:/some_folder/UniServer/msmtp/msmtp.exe --file=C:/some_folder/UniServer/msmtp/msmtprc.ini  -t"

Function run_location_tracker() located in file UniServer\unicon\main\includes\functions.php automatically updates paths in the three php.ini files. However file UniServer\msmtp\msmtprc.ini is new and needs adding to the above function as follows:

 if (file_exists($usf_msmtp)) {                         // Only update if exists 
   file_search_replace($usf_msmtp,$s_str,$base_f);      // Update msmpt ini
 }

Note: File $usf_msmtp is defined in UniServer\unicon\main\includes\config.inc.php. A user may delete msmtp and use an alternative. So the file's existence is check first; this prevents error messages.

Top

General note

At first sight, msmtp.exe looks large at 2.13 MB, however it is self contained and compares favourably with alternatives such as fake sendmail. sendmail.exe (828 KB) requires libeay32.dll (1.06 MB) and ssleay32.dll (208 KB) (=2.10 MB).

Top

Summary

For a home web server or small business server, the above is a very good compromise.

However for a portable server it is ideal. Include this with DtDNS and you can have a portable server with email capability on-line within ten minutes.

Top