วันจันทร์ที่ 31 พฤษภาคม พ.ศ. 2553

send e-mail with sSMTP


Ssmtp เป็นโปรแกรมส่งอีเมลแบบ CLI ที่ช่วยให้ Server สามารถส่งอีเมลได้โดยไม่ต้องตั้ง Mail Serverเอง คล้ายกับการใช้งาน Mail Client เช่น Outlook Express , ThunderBird
การ setup โดยใช้การส่งเมลผ่าน Thaicyberu Mail


ติดตั้งโปรแกรม
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
yum install ssmtp
service sendmail stop
chkconfig sendmail off
ใช้โปรแกรม ssmtp แทนการใช้ sendmail
ln -s /usr/local/ssmtp/sbin/ssmtp /usr/sbin/sendmail

ติดตั้งเสร็จเปิดไฟล์ ssmtp.conf
nano /etc/ssmtp/ssmtp.conf
แก้ไข/เพิ่มบรรทัดต่อไปนี้
..........................

root=admin@thaicyberu.go.th
mailhub=smtp.gmail.com:587
AuthUser=xxx@thaicyberu.go.th (email)
AuthPass=mypassword
UseSTARTTLS=YES
...........................

nano /etc/ssmtp/revaliases.conf
root:admin@thaicyberu.go.th:smtp.gmail.com:587
nobody:username@thaicyberu.go.th:smtp.gmail.com:587





SSMTP ส่งเมลได้แล้ว ทดลองส่งด้วยคำสั่ง
ssmtp myemail@gmail.com
ทดสอบการส่งข้อความ
To: recipient_email@example.com
From: myemailaddress@thaicyberu.go.th
Subject: test email
hello world!
เวลาส่งเมลก็ใช้คำสั่ง
$echo "this is a test" |mail -s "test" xxx@thaicyberu.go.th

การใช้งานกับ php เข้าไปแก้ไขใน php.ini
........................................................
[mail function]
; For Unix only. you may supply arguments as well (default:"sendmail -t -i")

sendmail_path = /usr/sbin/ssmtp -t






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

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