Views: 29180
Last Modified: 06.02.2015

This information will be useful for the manual setup and diagnostics of errors with the mail service.

Changes to Configuration Files

The setup uses the msmtp package (it is included in standard dependences for the package bitrix-env). The package provides for php module settings in the file /etc/php.d/bitrixenv.ini:

sendmail_path = msmtp -t -i

If the configuration is performed from the web interface or console-based menu:

  1. The configuration file /home/bitrix/.msmtprc is created or updated:
    # smtp account configuration for default
    account default
    logfile /home/bitrix/msmtp_default.log
    host 192.168.0.25
    port 25
    from name@site.com
    keepbcc on
    auth on
    user name@site.com
    password XXXXXXXXXXXXXX
    tls on
    tls_certcheck off
    
  2. The account named default is used by default for all websites. If a mailbox for a website other than default is being set up, changes are made to the Apache configuration file (website configuration file):
      <Directory /home/bitrix/www/> 
            ...     
            php_admin_value sendmail_path "msmtp -t -i -a site_name" 
     </Directory> 
    
  3. A symbolic link with /home/bitrix/.msmtprc at /etc/msmtprc is created (this action is necessary for mail sending jobs that are performed through crontab).

Scripts Used

These recommendations will be useful for testing the automation.

The script /opt/webdir/bin/bx-sites is used for creating from the Web or console.

During mail service setup, it accepts the following parameters:

 bx-sites -o json -a email --smtphost=smtp.yandex.com \
  --smtpuser='jhon@yandex.com' --password=XXXXXXXXXX \
  --email='jhon@yandex.com' --smtptls -s alice
где:
  • -a email – an action type we perform for the website (-h will permit to obtain the entire list available);
  • --smtphost - IP address or DNS host name through which the mail will be sent;
  • --smtpuser – user’s login (if this parameter is not used, it can be omitted);
  • --password – password for authorization at a mail server;
  • --email – the from field in the message;
  • --smtptls – includes TLS when sending mail;
  • -s|--site – website name (default will be used by default).

Problems and Solutions

The section describes the problems found and resolved and also the ways to debug mail-related problems.

  1. msmtp keeps a log of notices sent. For example, you may look up the log to find why a message was not sent:

    Spt 04 14:41:11 host=smtp.yandex.com tls=on auth=on user=bx@ya.com from=bx@ya.com recipients=3458@gmail.com smtpstatus=554  
    smtpmsg='554 5.7.1 Message rejected under suspicion of SPAM adxPcTaXWc-fB4SvmKU' errormsg='the server did not accept the mail' exitcode=EX_UNAVAILABLE 
    
  2. msmtp does not record the information if it failed to start or its configuration is incorrect. We execute message sending from We run sending from the console (we replace the recipient’s address with our address):
    echo -e "test message" | /usr/bin/msmtp --debug -t -i name@site.com
    
    an error can occur here, e.g. an error of configuration loading:
    ignoring system configuration file /etc/msmtprc: No such file or catalog
    ignoring user configuration file /.msmtprc: No such file or catalog
    falling back to default account
    

    In this case no configuration file was found, that is why sending failed.

  3. If everything is in order in clause 2 but messages still fail to go through:
    • Place the script test_email.sh to the catalog /usr/bin/ and set execution rights:
      #!/bin/bash
      export HOME=/home/bitrix
      
      tmp_dir=/tmp/mail
      
      args=$@
      if [[ ! -d $tmp_dir ]]; then
              mkdir $tmp_dir
              chmod 777 $tmp_dir
      fi
      
      message_body=""
      while read line; do
        message_body="$message_body$line\n"
      done < /dev/stdin
      
      tmp_file=$(mktemp $tmp_dir/$(date +%Y%m%d_%H%M%S)_XXXXXXXXX)
      
      echo "=========================================" > $tmp_file
      echo "ARGV: /usr/bin/msmtp --debug -t -i $args" >> $tmp_file
      echo "=========================================" >> $tmp_file
      echo -e "BODY: $message_body" >> $tmp_file
      echo "=========================================" >> $tmp_file
      
      # send message
      echo -e "$message_body" | /usr/bin/msmtp --debug -t -i $args >> $tmp_file && 2>&1
      
    • Change the mail settings in the configuration /etc/php.d/bitrixenv.ini:
      sendmail_path = /usr/bin/test_mail.sh
      
    • Restart apache.
    • This script launches msmtp with the debug option and stores information about sending parameters, body of the message, and command execution results for each message sent.

      When a message is created from the web interface, all of the information is stored in the catalog /tmp/mail, and each message will be stored in a separate file.


Problem:
Messages with notices about orders from a website fail to send, statistics for the day in BitrixVA v5.0.44-5.0.45.

Solution:
The reason is that the home catalog of the scripts is set in HOME=/, which is why the messages to be sent through a Cron job fail to send.
In order to solve the problem, you have to:
  • Create a symbolic link with /home/bitrix/.msmtprc at /etc/msmtprc – the configuration file /etc/msmtprc is a system file for the utility and permits to decide on the configuration file location with such a HOME parameter.
  • Or update BitrixVA to version 5.0.46 or higher.




Courses developed by Bitrix24