2

最初に次を使用して送信しようとしましたtelnet

$ telnet smtp.yandex.ru 25
Trying 77.88.21.38...
Connected to smtp.yandex.ru.
Escape character is '^]'.
220 smtp12.mail.yandex.net ESMTP (Want to use Yandex.Mail for your domain? Visit http://pdd.yandex.ru)
EHLO yandex.ru
250-smtp12.mail.yandex.net
250-8BITMIME
250-PIPELINING
250-SIZE 42991616
250-STARTTLS
250-AUTH LOGIN PLAIN
250-DSN
250 ENHANCEDSTATUSCODES
AUTH LOGIN
334 VXNlcm5hbWU6
bWFpbEBua3QubWU=
334 UGFzc3dvcmQ6
*******
235 2.7.0 Authentication successful.
MAIL FROM:mail@nkt.me  
250 2.1.0 <mail@nkt.me> ok
RCPT TO:dev@nkt.me
250 2.1.5 <dev@nkt.me> recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Subject: Q^BP5Q^AQ^B
To: dev@nkt.me
.
250 2.0.0 Ok: queued on smtp12.mail.yandex.net as 6VPPHaRoyW-LYnSwHm7
QUIT
221 2.0.0 Closing connection.
Connection closed by foreign host.

すべて問題ありません。メールを受け取りました。次に、swiftmailer パラメータをセットアップします。

mailer_transport: smtp
mailer_host:      smtp.yandex.ru
mailer_user:      mail@nkt.me
mailer_password:  *****
mailer_auth_mode:  login
mailer_encryption: ~
mailer_port:       25

そして、メールを送信するためのコマンドを作成します:

class SendMailCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('mail:send')
            ->setDescription('Send email')
            ->addOption('to', null, InputOption::VALUE_REQUIRED, 'Destination email address')
            ->addOption('body', 'b', InputOption::VALUE_REQUIRED, 'Mail body')
            ->addOption('subject', 'sub', InputOption::VALUE_OPTIONAL, 'Mail title');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $mailer = $this->getContainer()->get('mailer');
        $to = $input->getOption('to');
        $subject = $input->getOption('subject');
        $body = $input->getOption('body');
        $message = \Swift_Message::newInstance()
            ->setTo($to)
            ->setSubject($subject)
            ->setBody($body);
        $output->writeln('To: ' . $to);
        $output->writeln('Subject: ' . $subject);
        $output->writeln('Body: ' . $body);
        $output->writeln('Result: ' . $mailer->send($message));
    }
}

そしてそれを実行します:

$ app/console mail:send --to="dev@nkt.me" --body="Test body" --subject="Test"
To: dev@nkt.me
Subject: Test
Body: Test body
Result: 1

そうでなければ、私は質問を投稿しなかったでしょう。SSL を使用しようとしましたが、まだ機能していません。何が問題なのですか?

PS 今私はスプールの代わりに smtp を取得します:

protected function execute(InputInterface $input, OutputInterface $output)
{
    $mailer = $this->getContainer()->get('swiftmailer.transport.real');
    $message = \Swift_Message::newInstance()
        ->setFrom(['mail@nkt.me' => 'Admin'])
        ->setTo($input->getOption('to'))
        ->setSubject($input->getOption('subject'))
        ->setBody($input->getOption('body'));
    $output->writeln(sprintf('Sent %s emails', $mailer->send($message)));
}

しかし、エラーも発生します:

[Swift_TransportException]                                   
Expected response code 250 but got code "", with message "" 
4

1 に答える 1