4

I have a standard staging environment on a Ubuntu server (LAMP), with a couple of webpages on it.

There are some webpages that send Emails on particular workflow events.

I have to run few tests on the system, but can not allow random emails to fly over and spam the moderators (it happened once).

Disabling the particular part of the code, or adjusting the webpage settings is not good scenario, as the system need to be in a production-like setup, plus there may be in several places (or a fallback scenario if one of the options is disabled) and I can not risk it.

Most reasonable solution I can think of is to simple disable (temporary) all mailing services (commonly used with PHP).

I have full access on the server and basic Linux skills.

found this witch looks nice for start:

sudo /etc/init.d/sendmail stop

But I need to know how if there are other possible mail services,
how to check if they are running,
how to stop them,
how to validate.

I guess the above command will probably be enough... but I would like to hear the opinion of some one with more experience in the subject.

3
  • 1
    Just sending emails does usually depend on a locally running MTA (Mail-Transport-Agent, like sendmail). So, if you never configured a MTA on your system, it is unlikely that stopping it will prevent PHP from mailing. If you did configure it, you should know which one to stop. There are quite a few MTAs available in Ubuntu's repository (see section "Provided by" in the output of aptitude show mail-transport-agent).
    – Adaephon
    Aug 8, 2014 at 12:38
  • I did not configure the system, not sure what is on it (standard stuff for LAMP server). And there is some mail server working as the first test showed.
    – d.raev
    Aug 8, 2014 at 13:06
  • @d.raev if you feel a question has been closed wrongly, please post about it on Ask Ubuntu Meta instead of flagging. The community voted to close, not a moderator, so it's up to the community to reopen. That said, the best way to have your question reopened is to edit it to address the reason for which it was closed. You seem to be asking for a full list of mailing services. That is way, way too broad. There are dozens of possibilities.
    – terdon
    Aug 25, 2016 at 10:46

1 Answer 1

2

If you stop the whole mail server like this (/etc/init.d/sendmail stop) you may encounter some difficulties to test correctly your code. For instance, when going thru the action that sends mail, it may wait too long and generate timeout because the mail server is not up, leading to you thinking that your code is not functioning.

My personal approach on the subject is not to stop the mail server, but it is to act at code level and at system level :

  1. First of all, if you need to send mail, you don't need to have a full mail server like Sendmail or Postfix or Qmail installed. You can just install the ssmtp package which is enough to send mail using a mail relay configured into /etc/ssmtp/ssmtp.conf.
  2. If your application is sending mail by using a local binary like mail or sendmail, stopping the mail server may not be the solution : mails can be queued locally and if you start again the mail server, all the mails accumulated will be sent at once.
  3. My ideal solution would be to send mail using the SMTP protocol directly from your application, by connecting to an IP address and a port (default 25), possibly using username and password to provide authentication.
  4. If your application is able to send mail to a relay (being local or external), make sure that it is not hardcoded in your code but defined via a configuration file dedicated to your application. The same should apply for the destination e-mail addresses.
  5. If you respect the previous point, then you can build a staging server which a different e-mail configuration. The configuration of the staging server can be to send mail to your personal e-mail address.
  6. This approach as the advantages to allow you to test the e-mail functionalities too without disturbing the real destination of the production mails. Also you are sure you will don't create side effect of disabling a mail server.
1
  • Thanks for the roundup I was scared for something like "2.". Your approach is strong but in my case I don't know the application so good (only did some minor fixes). Editing mail workflow is out of question (it is working on the live, not touching it!), I looked in to the code but it is complex and not just commenting-one-row-task.
    – d.raev
    Aug 8, 2014 at 13:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.