ads

วันศุกร์ที่ 10 กรกฎาคม พ.ศ. 2558

MailCatcher สำหรับทดสอบ internal SMTP

MailCatcher สำหรับทดสอบ SMTP internal 

ต้องลง lib สำหรับใช้คำสั่ง gem ให้ได้เสียก่อน
#yum install rubygems
#yum groupinstall -y development
# gem install mailcatcher
** จะฟ้อง error ต้องการ i18n ให้ทำตาม link นี้
https://cleanclouds.wordpress.com/2014/12/20/error-error-installing-rails-i18n-requires-ruby-version-1-9-3/
# yum groupinstall -y development
# curl -L get.rvm.io | bash -s stable
จะฟ้อง
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.26.5.tgz' - 'https://github.com/wayneeseguin/rvm/releases/download/1.26.5/1.26.5.tar.gz.asc'!
try downloading the signatures:
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
or if it fails:
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
สั่ง
# curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
# curl -L get.rvm.io | bash -s stable
# source /etc/profile.d/rvm.sh
รอจนเสร็จตามด้วย เพื่อลง ruby
# rvm install 1.9.3
เมื่อเสร็จจะมีข้อความบอก ทดสอบดูเวอร์ชั่น ruby ว่าถูกต้องไหม
# ruby --version
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
ระบบ mailcatcher จะทำงานเป็น deamon ตาม lib ของ ruby

เมื่อพร้อมกลับมา install mailcatcher ได้แล้ว
# gem install mailcatcher
แล้วก็รอไป (นานมากกก)
หากเราจะทำการทดสอบด้วยการส่งเมล์ผ่านะโค๊ด PHP ให้เราเข้าไปแก้ configure ของ php.ini ในส่วนของ mail option เสียก่อน ดังนี้
# vi /etc/php.ini

smtp_port = 1025
sendmail_from = me@example.com
sendmail_path = /usr/local/rvm/gems/ruby-1.9.3-p551/bin/catchmail --smtp-ip 0.0.0.0 --smtp-port 1025 -f me@example.com

แล้วทำากร restart httpd หนึ่งรอบ
# /etc/init.d/httpd restart
เมื่อเรียบร้อยแล้วทำการ start การทำงาน ของ MailCatcher
# mailcatcher --http-ip 0.0.0.0 --smtp-port 1025
จะมีข้อความบอกว่า mailcatcher สตาร์ทและทำงานแล้ว
webbrowser ของ server ip นั้นและตามด้วยพอร์? 1080
ส่วน smtp ตั้งเป็น port 1025
เมือเข้าไป http://ipaddress:1080/ จะพบ browser แสดงเมล์ที่ส่งผ่าน smtp ที่เราทดสอบ
ต่อไปสร้างโค๊ด php ทดสอบในการส่งว่าจะเข้าหรือไม่ดังนี้
# vi mail.php
<?php $headers = 'From: webmaster@example.com'; mail('nobody@example.com', 'Test email using PHP', 'This is a test email message', $headers, '-fwebmaster@example.com'); ?>

แล้วทำการสั่งเพื่อทดสอบดู
# php mail.php
และกด refresh ดูหน้า http://ipaddress:1080/ จะเห็นว่า MailCatcher เก็บเมล์นั้นได้แล้ว


ไม่มีความคิดเห็น:

แสดงความคิดเห็น