5.3-Nano: msmtp: Difference between revisions
(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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | '''''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 | 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 | 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
5.x-Nano: Introduction | Cron | DtDNS | Database Backup | msmtp
|
|
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.
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.
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 |
|
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.
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 |
This account requires authentication hence your login details:
|
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.
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 |
This account requires authentication hence your login details:
|
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.
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.
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:
|
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.
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.
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.
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).
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.