Can't send emails when using linuxmint as a local server

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
colski
Level 2
Level 2
Posts: 52
Joined: Sun Jan 25, 2015 8:21 pm

Can't send emails when using linuxmint as a local server

Post by colski »

Hi,

I have installed the latest linux mint on a little server in my house.

I am doing some web development work and have set up apache, mysql and php on it.

I have created some test websites and some are in drupal and some in wordpress.

All local websites seem to be working fine apart from email.

Neither drupal nor wordpress is sending out emails from my local server.

Is there some setting I need to make in apache somewhere?

Or is there some program I need to download from ubuntu/linuxmint repositories to allow email to be sent from my local drupal and wordpress websites?

I hope someone can help.

Thanks,

Colski
colski
Level 2
Level 2
Posts: 52
Joined: Sun Jan 25, 2015 8:21 pm

Re: Can't send emails when using linuxmint as a local server

Post by colski »

Hi,

Thanks for the reply.

Basically, I am trying to create (as close as possible) a local web development server where I can test various web sites and modifications, etc, before making these changes on live websites.

I have no idea on how to manage a full blown server and the security implications of a live online webserver etc.

However, I have managed to get LAMP working very nicely locally.

The only main thing "missing" is a way to send emails from these local websites.

(Yes in drupal there are a few modules which you can use to enable you to hook up with online mail servers such as authsmtp etc)

But this isn't how it's done with the live websites. These use some kind of mail server software on the online servers which are managed by my hosting company. I guess these could be sendmail or postfix or similar.

I don't really need to become an expert in these for the purposes of site testing. I am hoping there is some mini version or something really easy I can install on my linuxmint box to do the same thing as that on a full blown server without the bells and whistles.

Any suggestions for this anyone?

Thanks.
Habitual
Level 13
Level 13
Posts: 4863
Joined: Sun Nov 21, 2010 8:31 pm
Location: 0.0.0.0

Re: Can't send emails when using linuxmint as a local server

Post by Habitual »

colski wrote:These use some kind of mail server software on the online servers which are managed by my hosting company. I guess these could be sendmail or postfix or similar.
and this removes the need for authentication to a valid smtp server, eg: they process it for you.
gmilo2 wrote:You could use Gmail, Yahoo, etc as your SMTP server. Otherwise you could look into postfix to run a local mail server.
Off their network, you will have to provide some means of sending email via authentication to a valid smtp server/host as suggested by gmilo2.

If you cannot provide one you could send mail to root or another local account on the box.
colski wrote:I can install on my linuxmint box to do the same thing as that on a full blown server without the bells and whistles.
One of those bells and whistles is the processing of mail.

You can't just send email from any box to any email address without some form of authentication.
colski
Level 2
Level 2
Posts: 52
Joined: Sun Jan 25, 2015 8:21 pm

Re: Can't send emails when using linuxmint as a local server

Post by colski »

Thanks for the replies!

I think I have come across a way to see the emails being sent and received without involving any external smtp services, or without modifying any drupal or wordpress installations. It involves setting up a "dummy" sendmail program (basically a mini script) which acts like sendmail in a way but just logs the emails locally and doesn't go anywhere else.

This allows you to see that drupal or wordpress email scripts and setting are working properly. Here's how:

First, create a folder for your outgoing mail. We will create it in under /var/log/ where all the logs are stored:

$ sudo mkdir /var/log/mail

Create file /usr/local/bin/sendmail using your favorite text editor, I normally use Nano editor:

$ sudo nano /usr/local/bin/sendmail

Add following PHP script to this new "sendmail" file:

#!/usr/bin/php
<?php
$input = file_get_contents('php://stdin');
preg_match('|^To: (.*)|', $input, $matches);
$filename = tempnam('/var/log/mail', $matches[1] . '.');
file_put_contents($filename, $input);

This is where the magic happens and emails sent from PHP are stored as textfiles. The email address is extracted from the full email using regular expression, and used as the filename base - the tempnam() function creates a random filename with the email address used as filename prefix. You can alter this part however you want, for example include a timestamp in the filename.

We need to link our PHP script to PHP's sendmail functionality. Edit your php.ini file and set the sendmail_path setting as following:

sendmail_path = /usr/local/bin/sendmail

If you use Ubuntu/Kubuntu 12.4, your php.ini file is normally located at /etc/php5/apache2/php.ini. You can find your php.ini location also using the phpinfo() function, where you look for "Loaded Configuration File" value in the function's output.

Now we need to set permissions for new files/folders:

$ sudo chmod 755 /usr/local/bin/sendmail
$ sudo chmod 777 /var/log/mail

Restart apache:

$ sudo /etc/init.d/apache2 restart

And that's it! You can now try to send an email using PHP's mail() function and check the /var/log/mail folder.

Here one will find copies of the email received and any automated reply sent that has been specified in the drupal or wordpress install.
------------------------

Credit goes to http://martinvalasek.com/blog/how-to-ca ... cal-server
for this solution.

It seems to work fine.

Colski
Habitual
Level 13
Level 13
Posts: 4863
Joined: Sun Nov 21, 2010 8:31 pm
Location: 0.0.0.0

Re: Can't send emails when using linuxmint as a local server

Post by Habitual »

Good job finding a workaround!
Post Reply

Return to “Newbie Questions”