動機
不想架mail server
過程
因為已經讓EC2去吃role了,所以這邊簡單的賦予EC2 SESrole就好了
很方便,完全不用再去call smtp了。官方文件
再賦予role AmazonSESFullAccess 權限就可以了

當然一些前置還要做,像是去aws console設定一下,驗證一下什麼的
他這邊有一些限制
就是你的from一定要是能收信的信箱
在你設定上去的時候他會寄驗證信給你
驗證設定
廢話不多說,直接測試
因為我在東京,東京沒有SES服務
所以只好默默地指定region...
[root@ip-10-128-110-42 opt]# aws --region us-west-2 ses send-email \
--from g23988@gmail.com \
--destination ToAddresses=wei.liu@104.com.tw \
--message 'Subject={Data="Hi Hi Hi~",Charset="utf8"},Body={Text={Data=string,Charset="utf8"},Html={Data=string,Charset="utf8"}}'
官方文件在這
接著用php sdk v3來接接看
composer什麼的php的用家應該用到爛了就不說了
一樣先指定region,不然東京的我用不到哭哭
$client = new \Aws\Ses\SesClient([
'version' => 'latest',
'region' => 'us-west-2'
]);
然後開始寄信囉
$result = $client->sendEmail(
[
'Destination' => [ // REQUIRED
'ToAddresses' => ['wei.liu@104.com.tw'],
],
'Message' => [ // REQUIRED
'Body' => [ // REQUIRED
'Html' => [
'Charset' => 'utf8',
'Data' => 'hihihi im string', // REQUIRED
],
],
'Subject' => [ // REQUIRED
'Charset' => 'utf8',
'Data' => 'hihihi from aws ses by php sdk', // REQUIRED
],
],
'Source' => 'wei.liu@104.com.tw', // REQUIRED
'Tags' => [
[
'Name' => 'Name', // REQUIRED
'Value' => 'testemail', // REQUIRED
],
// ...
],
]);
參數自己看文件,顆顆官方文件在這

留言
張貼留言