sendgridを利用し、IPをホワイトリストに追加して利用するのはセキュリティ上必須である。
しかし、接続元のIP設定を間違えたり、
モデムを変更した場合などログインできなくなる。
上記の場合は api_key を用いて
php から ip アドレスを追加してログインできるようにしよう。
前提として当該サーバーからはメールを送信できる状態である。
(認証済み)
参考
https://github.com/sendgrid/sendgrid-php/blob/main/examples/accesssettings/accesssettings.php
hoge.php
$sg = new SendGrid(env('SENDGRID_API_KEY'));
$request_body = json_decode('{
"ips": [
{
"ip": "82.122.28.23"
},
{
"ip": "37.126.154.*"
}
]
}');
try {
$response = $sg->client->access_settings()->whitelist()->post($request_body);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
これで指定したIPをホワイトリストに追加することが可能。