Menguji Kirim Email menggunakan Container PHP
📅 24 Maret 2023
Requirements
Memiliki alamat email, password email, url mail, port smtp. Diketahui :
- MAIL_SERVER=mail.example.co.id
- MAIL_PORT=465
- MAIL_SECURE=ssl
- MAIL_ACCOUNT=noreply@notif.example.co.id
- MAIL_ACCOUNT_PASSWORD=Passwordnyadisini!
- FROM_MAIL=noreply@notif.example.co.id
- SMTP_DEBUG=4
How to use
Sumber dari github https://github.com/lbgm/mail-with-php
- Cloning repositori
shell
git clone https://github.com/lbgm/mail-with-php.git- Masuk ke direktori
- Build image dan sesuaikan dengan akun email dan mail server
shell
docker build -t lbgm/mailer -f Dockerfile ./ --build-arg MAIL_SERVER=mail.example.co.id --build-arg MAIL_PORT=465 --build-arg MAIL_SECURE=ssl --build-arg MAIL_ACCOUNT=noreply@notif.example.co.id --build-arg MAIL_ACCOUNT_PASSWORD=Passwordnyadisini! --build-arg FROM_MAIL=noreply@notif.example.co.id --build-arg SMTP_DEBUG=4- Run container
shell
docker run -d -p 46531:80 --name email-test -v /etc/localtime:/etc/localtime:ro --restart=always lbgm/mailer:latest- Pastikan untuk konfigurasi file autentikasi email di
/var/www/html/apps/noreply.php
How to test
Bisa menggunakan postman versi web jika server tes ada ip public nya. Jika server lokal berarti postman harus diinstall dulu.
Alternatif terakhir bisa menggunakan curl.
shell
curl -H "Content-Type: application/json" -X POST -d '{
"title": "Pengumuman hadiah !",
"to_mail": "kirimi_aku@example.co.id",
"to_name": "3355 Notif",
"message": "Selamat pak, dapatki hadiah",
"from_name": "Selamat! Anda menang undian"
}' http://127.0.0.1:46531/send-mail/