cdli / CdliTwoStageSignup

Two-stage signup process for ZfcUser. Supports Zend\Db and Doctrine! Now up-to-date with latest ZfcUser (as of Oct 24th, 2012)
Other
19 stars 13 forks source link

SMTP Auth for sendVerificationEmailMessage #10

Open Newan opened 11 years ago

Newan commented 11 years ago

First of all, I'd like to thank you for the module. Unfortunately, emails are often recognized as spam when sent by sendmail. Therefore I'd like to send the mails by a Mailserver using SMTP-Auth. I tried to implement this feature, but I'm not shure if that is ok. I changed the following filed:

    /**
     * SMTP Mail with Auth or use SendMail
     * 
     * Options: 'SMTP-Auth, SendMail'
     * Default: SendMail
     * 
     */ 
    'mailTranfer' => 'SendMail',

    //'smtpOption' => array('name'              => 'localhost.localdomain',
    //                      'host'              => '127.0.0.1',
    //                      'connection_class'  => 'login',
    //                      'connection_config' => array(
    //                          'username' => 'user',
    //                          'password' => 'pass',
    //                          ),
    //                      ),          

ModuleOptions.php

    protected $mailTranfer = 'SendMail';
    protected $smtpOption = '';

    public function setMailTranfer($mailTranfer)
    {
        $this->mailTranfer = $mailTranfer;
        return $this;
    }

    public function getMailTranfer()
    {
        return $this->mailTranfer;
    }

    public function setSmtpOption(array $option)
    {
        $this->smtpOption = $option;
        return $this;
    }

    public function getSmptOption()
    {
        return $this->smtpOption;
    }

EmailOptionsInterface.php

    public function setMailTranfer($mailTranfer);
    public function getMailTranfer();
    public function setSmtpOption(array $smtpOption);
    public function getSmptOption();

EmailVerification.php

use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;

EmailVerification.php

        //$this->emailTransport->send($message);

        if($this->getEmailMessageOptions()->getMailTranfer() == 'SMTP-Auth'){
          $this->setMessageTransport(new SmtpTransport());
          $this->emailTransport->setOptions(new SmtpOptions($this->getEmailMessageOptions()->getSmptOption()));
          $this->emailTransport->send($message);
        }else{
          $this->emailTransport->send($message);
        }

Maybe there is a more simple way to achive this functionality by overwriting the sendmail-function at this part of the code?

                'Zend\Mail\Transport\Sendmail' => function($sm) {
                    return new \Zend\Mail\Transport\Sendmail();
                }
dperjar commented 11 years ago

I'd be interested in trying this as well, would love to hear if someone has tried.

adamlundrigan commented 11 years ago

Thanks for the suggestion. I will take a look at what you've suggested and integrated it with the existing codebase

ezpaider commented 11 years ago

@Newan This works like a charm with Gmail but it's failing with Zoho. Any idea why?

ezpaider commented 11 years ago

Nevermind, just figured it out!! Thanks for everything