Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Missing Mail configuration #1

Closed
kimek opened this issue Jul 12, 2017 · 14 comments
Closed

Documentation: Missing Mail configuration #1

kimek opened this issue Jul 12, 2017 · 14 comments

Comments

@kimek
Copy link

kimek commented Jul 12, 2017

Hi Guys,
Do we need any of
MAIL_DRIVER=smtp
MAIL_HOST=mail
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

to run mailjet ?

Other question, does the alias is neccessery ? If yes where it sohuld go in Lumen in this case ?

Thank you

Regards

@Nightbr
Copy link
Member

Nightbr commented Jul 12, 2017

Hi,

if you don't want to use the mail transport mailjet, you don't need the MAIL_XX config.
If you don't want to use the mail transport, don't add this to your providers array:
Mailjet\LaravelMailjet\MailjetMailServiceProvider::class,

Can you give us some code of your integration ?

@kimek
Copy link
Author

kimek commented Jul 12, 2017

#env
MAIL_DRIVER=mailjet
MAIL_HOST=in-v3.mailjet.com
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

MAILJET_APIKEY={{ key }}
MAILJET_APISECRET={{ secret }}

#app.php

$app->configure('mail');
$app->configure('services');

$app->register(Mailjet\LaravelMailjet\MailjetServiceProvider::class);
$app->register(Mailjet\LaravelMailjet\MailjetMailServiceProvider::class);

#services.php

return [
'mailjet' => [
'key' => env('MAILJET_APIKEY'),
'secret' => env('MAILJET_APISECRET'),
]
];

#mail
return [

'driver' => env('MAIL_DRIVER', 'smtp'),

'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

'port' => env('MAIL_PORT', 587),

'from' => ['address' => 'noreply@emporium.co.uk', 'name' => 'No Reply'],

'encryption' => env('MAIL_ENCRYPTION', 'tls'),

'username' => env('MAIL_USERNAME'),

'password' => env('MAIL_PASSWORD'),

'sendmail' => '/usr/sbin/sendmail -bs',

];

@Nightbr
Copy link
Member

Nightbr commented Jul 12, 2017

Sounds good, in fact, you only need to set this config for Mailjet mail client works:

MAIL_DRIVER=mailjet
MAILJET_APIKEY={{ key }}
MAILJET_APISECRET={{ secret }}

@kimek
Copy link
Author

kimek commented Jul 12, 2017

Thanks for fast replay @Nightbr

Mailhog works fine, Im trying to get mail now with Mailjet and nothing.

Double check key/secret.

In this case maybe there is issue with my docker <-> network.

I will check that. If there will be no comment below it means that it was firewall/network issue.

@Nightbr
Copy link
Member

Nightbr commented Jul 12, 2017

Humm, can you copy/paste your code where you try to sent mail ?
Also make sure you have a valid and authorised from-address configured on your Mailjet account.

@kimek
Copy link
Author

kimek commented Jul 12, 2017

Mail::raw('Raw string email', function($msg) { $msg->to(['test@{{ domain which is added to MJ }}']); $msg->from(['test@{{ domain which is added to MJ }}']); });

@Nightbr
Copy link
Member

Nightbr commented Jul 12, 2017

ok, it should work so.
In order to debug deeper, you can try to var_dump() into vendor/mailjet/SwiftMailer/MailjetTransport.php into the send method, you can var_dump($this->resultApi); around line 140.

@kimek
Copy link
Author

kimek commented Jul 17, 2017

var dump on

$this->resultApi = $this->mailjetClient->post(Resources::$Email, ['body' => $mailjetMessage]);

object(Mailjet\Response)#165 (5) {
  ["status":"Mailjet\Response":private]=>
  int(500)
  ["success":"Mailjet\Response":private]=>
  bool(false)
  ["body":"Mailjet\Response":private]=>
  NULL
  ["rawResponse":"Mailjet\Response":private]=>
  object(GuzzleHttp\Psr7\Response)#163 (6) {
    ["reasonPhrase":"GuzzleHttp\Psr7\Response":private]=>
    string(35) "Cannot convert data from Null value"
    ["statusCode":"GuzzleHttp\Psr7\Response":private]=>
    int(500)
    ["headers":"GuzzleHttp\Psr7\Response":private]=>
    array(4) {
      ["Date"]=>
      array(1) {
        [0]=>
        string(29) "Mon, 17 Jul 2017 11:01:04 GMT"
      }
      ["Vary"]=>
      array(1) {
        [0]=>
        string(15) "Accept-Encoding"
      }
      ["Content-Length"]=>
      array(1) {
        [0]=>
        string(1) "0"
      }
      ["Content-Type"]=>
      array(1) {
        [0]=>
        string(9) "text/html"
      }
    }
    ["headerNames":"GuzzleHttp\Psr7\Response":private]=>
    array(4) {
      ["date"]=>
      string(4) "Date"
      ["vary"]=>
      string(4) "Vary"
      ["content-length"]=>
      string(14) "Content-Length"
      ["content-type"]=>
      string(12) "Content-Type"
    }
    ["protocol":"GuzzleHttp\Psr7\Response":private]=>
    string(3) "1.1"
    ["stream":"GuzzleHttp\Psr7\Response":private]=>
    object(GuzzleHttp\Psr7\Stream)#161 (7) {
      ["stream":"GuzzleHttp\Psr7\Stream":private]=>
      resource(6) of type (stream)
      ["size":"GuzzleHttp\Psr7\Stream":private]=>
      int(0)
      ["seekable":"GuzzleHttp\Psr7\Stream":private]=>
      bool(true)
      ["readable":"GuzzleHttp\Psr7\Stream":private]=>
      bool(true)
      ["writable":"GuzzleHttp\Psr7\Stream":private]=>
      bool(true)
      ["uri":"GuzzleHttp\Psr7\Stream":private]=>
      string(10) "php://temp"
      ["customMetadata":"GuzzleHttp\Psr7\Stream":private]=>
      array(0) {
      }
    }
  }
  ["request"]=>
  object(Mailjet\Request)#138 (7) {
    ["method":"Mailjet\Request":private]=>
    string(4) "POST"
    ["url":"Mailjet\Request":private]=>
    string(31) "https://api.mailjet.com/v3/send"
    ["filters":"Mailjet\Request":private]=>
    array(0) {
    }
    ["body":"Mailjet\Request":private]=>
    array(5) {
      ["FromEmail"]=>
      string(19) "{{mailAdress}}"
      ["FromName"]=>
      NULL
      ["Subject"]=>
      NULL
      ["Recipients"]=>
      array(1) {
        [0]=>
        array(2) {
          ["Email"]=>
          string(19) "{{mailAddress}}"
          ["Name"]=>
          NULL
        }
      }
      ["Text-part"]=>
      string(16) "Raw string email"
    }
    ["auth":"Mailjet\Request":private]=>
    array(2) {
      [0]=>
      string(32) "{{api_key}}"
      [1]=>
      string(32) "{{api secret}}
    }
    ["type":"Mailjet\Request":private]=>
    string(16) "application/json"
    ["config":"GuzzleHttp\Client":private]=>
    array(8) {
      ["defaults"]=>
      array(1) {
        ["headers"]=>
        array(1) {
          ["user-agent"]=>
          string(48) "mailjet-apiv3-php/7.0.15-0ubuntu0.16.04.4/v1.2.0"
        }
      }
      ["handler"]=>
      object(GuzzleHttp\HandlerStack)#139 (3) {
        ["handler":"GuzzleHttp\HandlerStack":private]=>
        object(Closure)#146 (2) {
          ["static"]=>
          array(2) {
            ["default"]=>
            object(Closure)#144 (2) {
              ["static"]=>
              array(2) {
                ["default"]=>
                object(GuzzleHttp\Handler\CurlMultiHandler)#140 (5) {
                  ["factory":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
                  object(GuzzleHttp\Handler\CurlFactory)#141 (2) {
                    ["handles":"GuzzleHttp\Handler\CurlFactory":private]=>
                    array(0) {
                    }
                    ["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=>
                    int(50)
                  }
                  ["selectTimeout":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
                  int(1)
                  ["active":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
                  NULL
                  ["handles":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
                  array(0) {
                  }
                  ["delays":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
                  array(0) {
                  }
                }
                ["sync"]=>
                object(GuzzleHttp\Handler\CurlHandler)#142 (1) {
                  ["factory":"GuzzleHttp\Handler\CurlHandler":private]=>
                  object(GuzzleHttp\Handler\CurlFactory)#143 (2) {
                    ["handles":"GuzzleHttp\Handler\CurlFactory":private]=>
                    array(1) {
                      [0]=>
                      resource(8) of type (curl)
                    }
                    ["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=>
                    int(3)
                  }
                }
              }
              ["parameter"]=>
              array(2) {
                ["$request"]=>
                string(10) "<required>"
                ["$options"]=>
                string(10) "<required>"
              }
            }
            ["streaming"]=>
            object(GuzzleHttp\Handler\StreamHandler)#145 (1) {
              ["lastHeaders":"GuzzleHttp\Handler\StreamHandler":private]=>
              array(0) {
              }
            }
          }
          ["parameter"]=>
          array(2) {
            ["$request"]=>
            string(10) "<required>"
            ["$options"]=>
            string(10) "<required>"
          }
        }
        ["stack":"GuzzleHttp\HandlerStack":private]=>
        array(4) {
          [0]=>
          array(2) {
            [0]=>
            object(Closure)#147 (1) {
              ["parameter"]=>
              array(1) {
                ["$handler"]=>
                string(10) "<required>"
              }
            }
            [1]=>
            string(11) "http_errors"
          }
          [1]=>
          array(2) {
            [0]=>
            object(Closure)#148 (1) {
              ["parameter"]=>
              array(1) {
                ["$handler"]=>
                string(10) "<required>"
              }
            }
            [1]=>
            string(15) "allow_redirects"
          }
          [2]=>
          array(2) {
            [0]=>
            object(Closure)#149 (1) {
              ["parameter"]=>
              array(1) {
                ["$handler"]=>
                string(10) "<required>"
              }
            }
            [1]=>
            string(7) "cookies"
          }
          [3]=>
          array(2) {
            [0]=>
            object(Closure)#150 (1) {
              ["parameter"]=>
              array(1) {
                ["$handler"]=>
                string(10) "<required>"
              }
            }
            [1]=>
            string(12) "prepare_body"
          }
        }
        ["cached":"GuzzleHttp\HandlerStack":private]=>
        object(Closure)#158 (2) {
          ["static"]=>
          array(1) {
            ["handler"]=>
            object(GuzzleHttp\RedirectMiddleware)#157 (1) {
              ["nextHandler":"GuzzleHttp\RedirectMiddleware":private]=>
              object(Closure)#156 (2) {
                ["static"]=>
                array(1) {
                  ["handler"]=>
                  object(GuzzleHttp\PrepareBodyMiddleware)#154 (1) {
                    ["nextHandler":"GuzzleHttp\PrepareBodyMiddleware":private]=>
                    object(Closure)#146 (2) {
                      ["static"]=>
                      array(2) {
                        ["default"]=>
                        object(Closure)#144 (2) {
                          ["static"]=>
                          array(2) {
                            ["default"]=>
                            object(GuzzleHttp\Handler\CurlMultiHandler)#140 (5) {
                              ["factory":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
                              object(GuzzleHttp\Handler\CurlFactory)#141 (2) {
                                ["handles":"GuzzleHttp\Handler\CurlFactory":private]=>
                                array(0) {
                                }
                                ["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=>
                                int(50)
                              }
                              ["selectTimeout":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
                              int(1)
                              ["active":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
                              NULL
                              ["handles":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
                              array(0) {
                              }
                              ["delays":"GuzzleHttp\Handler\CurlMultiHandler":private]=>
                              array(0) {
                              }
                            }
                            ["sync"]=>
                            object(GuzzleHttp\Handler\CurlHandler)#142 (1) {
                              ["factory":"GuzzleHttp\Handler\CurlHandler":private]=>
                              object(GuzzleHttp\Handler\CurlFactory)#143 (2) {
                                ["handles":"GuzzleHttp\Handler\CurlFactory":private]=>
                                array(1) {
                                  [0]=>
                                  resource(8) of type (curl)
                                }
                                ["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=>
                                int(3)
                              }
                            }
                          }
                          ["parameter"]=>
                          array(2) {
                            ["$request"]=>
                            string(10) "<required>"
                            ["$options"]=>
                            string(10) "<required>"
                          }
                        }
                        ["streaming"]=>
                        object(GuzzleHttp\Handler\StreamHandler)#145 (1) {
                          ["lastHeaders":"GuzzleHttp\Handler\StreamHandler":private]=>
                          array(0) {
                          }
                        }
                      }
                      ["parameter"]=>
                      array(2) {
                        ["$request"]=>
                        string(10) "<required>"
                        ["$options"]=>
                        string(10) "<required>"
                      }
                    }
                  }
                }
                ["parameter"]=>
                array(2) {
                  ["$request"]=>
                  string(10) "<required>"
                  ["$options"]=>
                  string(10) "<required>"
                }
              }
            }
          }
          ["parameter"]=>
          array(2) {
            ["$request"]=>
            string(10) "<required>"
            ["$options"]=>
            string(10) "<required>"
          }
        }
      }
      ["allow_redirects"]=>
      array(5) {
        ["max"]=>
        int(5)
        ["protocols"]=>
        array(2) {
          [0]=>
          string(4) "http"
          [1]=>
          string(5) "https"
        }
        ["strict"]=>
        bool(false)
        ["referer"]=>
        bool(false)
        ["track_redirects"]=>
        bool(false)
      }
      ["http_errors"]=>
      bool(true)
      ["decode_content"]=>
      bool(true)
      ["verify"]=>
      bool(true)
      ["cookies"]=>
      bool(false)
      ["headers"]=>
      array(1) {
        ["User-Agent"]=>
        string(56) "GuzzleHttp/6.2.1 curl/7.47.0 PHP/7.0.15-0ubuntu0.16.04.4"
      }
    }
  }
}

@kimek
Copy link
Author

kimek commented Jul 17, 2017

This works fine (just to inform)

curl -s \
  -X POST \
  --user "{{key}}" \
  https://api.mailjet.com/v3/send \
  -H 'Content-Type: application/json' \
  -d '{
    "FromEmail":"{{emailAddress}}",
    "Text-part":"Raw string email",
    "Recipients":[
        {
            "Email": "{{emailAddress}}"
        }
    ]
  }'

@Nightbr
Copy link
Member

Nightbr commented Jul 17, 2017

@arnaudbreton, @latanasov, it seems like the API doesn't like NULL value:

Cannot convert data from Null value

Body request:

 ["body":"Mailjet\Request":private]=>
    array(5) {
      ["FromEmail"]=>
      string(19) "{{mailAdress}}"
      ["FromName"]=>
      NULL
      ["Subject"]=>
      NULL
      ["Recipients"]=>
      array(1) {
        [0]=>
        array(2) {
          ["Email"]=>
          string(19) "{{mailAddress}}"
          ["Name"]=>
          NULL
        }
      }
      ["Text-part"]=>
      string(16) "Raw string email"
    }

I think it can be better if the API could handle NULL value. But as a workaround, we can manage it into our SwiftMailerTransport...

@kimek try to add subject to your $msg:

$msg->subject('test');

https://laravel.com/api/5.3/Illuminate/Mail/Message.html

@kimek
Copy link
Author

kimek commented Jul 17, 2017

@Nightbr
Same stuff:

object(Mailjet\Response)#165 (5) {
  ["status":"Mailjet\Response":private]=>
  int(500)
  ["success":"Mailjet\Response":private]=>
  bool(false)
  ["body":"Mailjet\Response":private]=>
  NULL
  ["rawResponse":"Mailjet\Response":private]=>
  object(GuzzleHttp\Psr7\Response)#163 (6) {
    ["reasonPhrase":"GuzzleHttp\Psr7\Response":private]=>
    string(35) "Cannot convert data from Null value"
    ["statusCode":"GuzzleHttp\Psr7\Response":private]=>
    int(500)
    ["headers":"GuzzleHttp\Psr7\Response":private]=>
    array(4) {
      ["Date"]=>
      array(1) {
        [0]=>
        string(29) "Mon, 17 Jul 2017 11:30:53 GMT"
      }
      ["Vary"]=>
      array(1) {
        [0]=>
        string(15) "Accept-Encoding"
      }
      ["Content-Length"]=>
      array(1) {
        [0]=>
        string(1) "0"
      }
      ["Content-Type"]=>
      array(1) {
        [0]=>
        string(9) "text/html"
      }
    }
    ["headerNames":"GuzzleHttp\Psr7\Response":private]=>
    array(4) {
      ["date"]=>
      string(4) "Date"
      ["vary"]=>
      string(4) "Vary"
      ["content-length"]=>
      string(14) "Content-Length"
      ["content-type"]=>
      string(12) "Content-Type"
    }
    ["protocol":"GuzzleHttp\Psr7\Response":private]=>
    string(3) "1.1"
    ["stream":"GuzzleHttp\Psr7\Response":private]=>
    object(GuzzleHttp\Psr7\Stream)#161 (7) {
      ["stream":"GuzzleHttp\Psr7\Stream":private]=>
      resource(5) of type (stream)
      ["size":"GuzzleHttp\Psr7\Stream":private]=>
      int(0)
      ["seekable":"GuzzleHttp\Psr7\Stream":private]=>
      bool(true)
      ["readable":"GuzzleHttp\Psr7\Stream":private]=>
      bool(true)
      ["writable":"GuzzleHttp\Psr7\Stream":private]=>
      bool(true)
      ["uri":"GuzzleHttp\Psr7\Stream":private]=>
      string(10) "php://temp"
      ["customMetadata":"GuzzleHttp\Psr7\Stream":private]=>
      array(0) {
      }
    }
  }

@latanasov
Copy link
Contributor

@Nightbr @kimek , I'll fix the NULL value issue on the SwiftMailerTransport side. I think we already have a bug reported on the API backend.

@kimek could you try setting Subject, From name and To name to an empty string for example ("") and say if the issue is resolved.

@kimek
Copy link
Author

kimek commented Jul 17, 2017

@Nightbr true, it didn't like Null.
I've added subject and name to email address and it works fine


$app->get('/mail', function () use ($app) {
    Mail::raw('Raw string email', function($msg) { 
           $msg->to(['{{clientEmailAddress}}']); 
           $msg->subject('{{subjectName}}); 
           $msg->setFrom(['{{emailAddress}}'=> '{{emailName}}']);
    });
});

Setting up only subject didn't fix issue. I've needed to add name to 'from-email'.

Thanks @Nightbr , thanks @latanasov

@latanasov
Copy link
Contributor

Hi @kimek we just released the improved version. You can update the library with composer update mailjet/mailjet-swiftmailer . Do let us know if you experience any other issues .

Regards,
Lyubo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants