通过Botman Studio发送邮件

时间:2019-05-17 16:39:04

标签: laravel bots

我正在使用laravel,botman studio和电报API开发聊天机器人,我需要向gmail发送电子邮件。

当我使用botman / tinker进行测试时,可以发送电子邮件

但是当我用自动电报进行测试时,它不起作用。

我在这里留下了我正在使用的部分代码,我不知道这是否是因为botman studio的Conversation类不接受Mailable类,您能帮我吗?

这是我的代码:

  <? php

  namespace App \ Conversations;

  use Illuminate \ Foundation \ Inspiring;
  use BotMan \ BotMan \ Messages \ Incoming \ Answer;
  use BotMan \ BotMan \ Messages \ Outgoing \ Question;
  use BotMan \ BotMan \ Messages \ Outgoing \ Actions \ Button;
  use BotMan \ BotMan \ Messages \ Conversations \ Conversation;
  use App \ Products;
  use App \ config \ botman \ config;
  use Illuminate \ Support \ Facades \ Mail;
  use Illuminate \ Support \ Facades \ View;


  class testsbot extends Conversation
  {

  / **
  * Start the conversation.
  *
  * @return mixed
  * /
  public function run ()
  {
  $ this-> askEmail ();
  }


  private function askEmail () {

  $ this-> ask ('Enter the email', function (Answer $ answer) {
  // Save result
  $ this-> valueEmail = $ answer-> getText ();
  $ this-> configLenguage ();

  });


  }

  public function configLenguage ()
  {

  $ object = \ App \ Products :: select ('id', 'code', 'stocks') -> where ('status', '=', 'ACTIVE') -> get ();
  $ email = $ this-> valueEmail;
  Mail :: to ($ email) -> send (new Mailes ($ object));

  $ this-> say ('works');
  }

  }

  ?>

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class DemoEmail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * The demo object instance.
     *
     * @var Demo
     */
    public $demo;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($demo)
    {
        $this->demo = $demo;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->from('andi.am770@gmail.com')
                    ->view('mails.demo')
                    ->text('mails.demo_plain')
                    ->with(
                    [
                           'testVarOne' => '1',
                           'testVarTwo' => '2',
                     ]);

    }
}

0 个答案:

没有答案