Suitecrm: User defined smtp settings not used when sending email (ver 7.9)

Created on 2 Jun 2017  路  3Comments  路  Source: salesagility/SuiteCRM

Issue

I am referring to the Mail Account settings that can be found in the User profile (Profile - scroll all the way down - Settings - Mail Accounts - Add or Edit)
Here the user can add new SMTP settings; then the user can Add or Edit a Mail Account and specify these SMTP settings to be used with that mail account. This step works fine and settings are saved.

Expected Behavior

After defining SMTP settings and attaching them to a Mail Account as per above, one would expect emails sent from that Mail account to use the SMTP settings as defined.

Actual Behavior

This is not happening. The system smtp settings are used instead.

Possible Fix

First I confirmed that the smtp selection is correctly stored in the database along with the other settings in the inbound_email table. No problem here.
I could see that an id in the form of random key var_char is there to identify each record -- we shall call it inbound_email_id.
I then checked the email composer form (when you go to email - compose) and I saw that it properly lets you select your email address and sets the correct inbound_email_id in a hidden form element which is then submitted. All good so far.
Then I think I found an issue in modules/Emails/vardefs.php: there is no definition for the inbound_email_id that I could find, so that inbound_email_id form submission has nowhere to go...
So I created one by adding:

        'inbound_email_id' => array(
            'name' => 'inbound_email_id',
            'type' => 'varchar',
            'source' => 'non-db',
            'inline_edit' => false,

So now the bean engine does its magic and sets the bean inbound_email_id from the $_REQUEST data
Then next issue in line is the send() function in Emails.php
The send() function calls the setMailer() function which is the function that sets the smtp settings (among other things).
Here is setMailer definition
function setMailer($mail, $mailer_id='', $ieId='')
I could see that its third parameter $ieId is there to provide the inbound_email_id as one way to identify the from account. Indeed when I feed it the inbound_email_id manually it works great and sends via the correct smtp settings.
So in send() function of Email.php I replace

$mail = $this->setMailer($mail);

with

$ieId = $this->inbound_email_id;
$mail = $this->setMailer($mail,'',$ieId);

And that does the trick. Emails are now sent through the smtp settings specified with the corresponding inbound email settings.

Steps to Reproduce


  1. You need a way to know which SMTP server is used when sending. An easy way is to use gmail smtp because it will always set the from_address to the smtp user; make sure you use one gmail or google apps account for the system smtp
  2. Under a test user, create a new entry under Outgoing SMTP Mail Servers under Profile - scroll all the way down - Settings - Mail Accounts; here make sure to use another gmail or google apps account so that it will be clear whether that smtp user is used or not when receiving email.
  3. Create or edit the corresponding incoming account under Mail account, select SMTP settings created previously. Save all and close.
  4. Compose new email and send to an email address you can access. Check email and notice from info is from system smtp userid.

Your Environment

  • SuiteCRM Version used: 7.9
  • Browser: Chrome Version Version 58.0.3029.110 (64-bit)
  • Environment name and version : MySQL 5.7.18, PHP 5.6
  • Operating System and version: Ubuntu 16.04
Important Fix Proposed Bug

Most helpful comment

Submitted a pull request (my first!)

I ended up not going the inbound_email_record route because inbound_email_id is used all over the place, so I guess we have to live with both.

All 3 comments

@dawansv Excellent fix. Have you ever made a pull request?

Yes looking at doing a pull request. Was looking at that in the doc at https://suitecrm.com/wiki/index.php/Contributing_to_SuiteCRM

Regarding my fix, I saw afterwards that there is an 'inbound_email_record' variable defined in vardefs. and I think it is for the same purpose. I see it used when viewing an email for instance, and the value is the same reference to the id found in the inbound_email MySQL table.

So I think the solution should be to use 'inbound_email_record' as to not create 2 variables with the same meaning. In that case the compose form has to be updated to replace all references of inbound_email_id into inbound_email_record, then vardefs can stay as it is and the assignment to get $ieId replaced with $ieId = $this->inbound_email_record;

Submitted a pull request (my first!)

I ended up not going the inbound_email_record route because inbound_email_id is used all over the place, so I guess we have to live with both.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mausino picture Mausino  路  3Comments

Mausino picture Mausino  路  3Comments

ArturoBurela picture ArturoBurela  路  3Comments

darouca picture darouca  路  3Comments

connorshea picture connorshea  路  3Comments