Jump to content
X2Community Forums

Unable to use email alias in gmail


Recommended Posts

Through Google Workspace, I've set up an email alias as the default for my gmail account. I'd like to use this email alias for outgoing emails from X2. However, it seems to ignore the alias and sends emails using the original account email. I did figure out a workaround that requires 2 adjustments to the X2 code:

1. A separate "user" login entry is required for Google to distinguish between the email and login. 

In /protected/models/embedded/GMailAccount.php, add the "user" input in the functions below:

    public function attributeLabels(){
        return array(
            'senderName' => Yii::t('app','Sender Name'),
            'email' => Yii::t('app','Email Address'),
            'user' => Yii::t('app', 'Google ID'),
            'password' => Yii::t('app','Password'),
            'imapPort' => Yii::t('app','IMAP Port'),
            'imapServer' => Yii::t('app','IMAP Server'),
            'imapSecurity' => Yii::t('app','IMAP Security'),
            'imapNoValidate' => Yii::t('app','Disable SSL Validation'),
            'disableInbox' => Yii::t('app','Disable Email Inbox'),
        );
    }
    public function renderInput ($attr) {
        switch($attr){
            case 'user':
            case 'email':
                echo '<p class="fieldhelp-thin-small">'.Yii::t('app', '(example@gmail.com)').
                    '</p>';
                echo CHtml::activeTextField($this, $attr, $this->htmlOptions($attr));
                break;
            case 'password':
                echo X2Html::x2ActivePasswordField ($this, $attr, $this->htmlOptions ($attr), true);
                break;
            default:
                parent::renderInput ($attr);
        }
    }
   public function renderInputs(){
        $this->password = null;
        echo CHtml::activeLabel($this, 'senderName');
        $this->renderInput ('senderName');
        echo CHtml::activeLabel($this, 'email');
        $this->renderInput ('email');
        echo CHtml::activeLabel ($this, 'user');
        $this->renderInput ('user');
        echo CHtml::activeLabel($this, 'password');
        $this->renderInput ('password');
        echo '<br/>';
        echo '<br/>';
                echo CHtml::tag ('h3', array (), Yii::t('app', 'IMAP Configuration'));
        echo '<hr/>';
        echo CHtml::activeLabel($this, 'imapPort');
        $this->renderInput ('imapPort');
        echo CHtml::activeLabel($this, 'imapSecurity');
        $this->renderInput ('imapSecurity');
        echo CHtml::activeLabel($this, 'imapNoValidate');
        $this->renderInput ('imapNoValidate');
        echo CHtml::activeLabel($this, 'imapServer');
        $this->renderInput ('imapServer');
        echo CHtml::activeLabel($this, 'disableInbox');
        $this->renderInput ('disableInbox');
        echo CHtml::errorSummary($this);
    }

    public function rules(){
        return array(
            array('email','email'),
            array('senderName,user,email,password', 'required'),
            array('senderName,user,email,password,imapPort,imapSecurity,imapNoValidate,imapServer,disableInbox', 'safe'),
        );
    }

2. The "user" login needs to be added to the imap login.

In protected/modules/emailInboxes/models/EmailInboxes.php, pass the auth->user instead of auth->email.


    /**
     * Initialize a mailbox and connect via IMAP
     * @return boolean Whether the IMAP connection was successfully initialized
     */
    public function open($folder = "INBOX") {
        $this->setCurrentFolder ($folder);
        $cred = $this->credentials;
        $this->_imapStream = @imap_open(
            $this->encodeMailboxString($this->mailbox.$folder),
            !empty($cred->auth->user) ? $cred->auth->user : $cred->auth->email,
            $cred->auth->password);
        if (is_resource($this->_imapStream)) {
            $this->_open = true;
            return true;
        }
        return false;
    }

I've tested these changes and seem to be working now. 

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...