Wednesday, September 18, 2013

Gửi mail nội bộ dùng sendmail

Để cảnh báo các sự kiện tiến trình xảy ra ở Server, có thể viết scripts trong đó có gửi 1 message tới mail của Admin, để OS có thể gửi mail tới Admin các bạn cấu hình sendmail theo các bước bên dưới:
I. Thông dải
 Configure mail server cho phép dải IP máy chủ gửi mail, việc này phải nhờ network admin
Nếu không bạn sẽ gặp lỗi sau:
454 5.7.3 Client does not have permission to submit mail to this server.
II. Cấu hình Sendmail
Sendmail là 1 MTA ( Mail Transfer Agent) dùng giao thức SMTP để đóng vai trò là 1 SMTP server làm nhiệm vụ định tuyến trong việc gửi thư. Nó nhận mail từ những MUA ( Mail user agent ) và MTA khác, sau đó chuyển mail đến các MTA trên máy khác hay MTA trên máy của mình.
Sendmail hầu như đều đã được tích hợp sẵn trong các phiên bản Linux do đó bạn có thể cài đặt sendmail thông qua các file rpm. Để cài đặt sendmail với những tính năng cơ bản bạn cần hai file rpm sendmail và sendmail-cf .
Setup 2 package sau nếu chưa được install:  sendmail-cf-8.13.1-2.i386.rpm , m4-1.4.1-16.src.rpm
Chạy dịch vụ bằng lệnh
/etc/init.d/sendmail start
Kiểm tra xem sendmail đã chạy chưa bằng lệnh
netstat -an | grep :25 | grep tcp
nếu thấy trả về
tcp 0   0 127.0.0.1:25    0.0.0.0:*    LISTEN
Nghĩa là dịch vụ sendmail đã được cài đặt đúng và đang chạy trên hệ thống
Configure file /etc/resolv.conf
File này lưu các thông số cấu hình của DNS client.Nếu Mail server xử lý mail trên máy hostname cotech.kvs.org.vn và địa chỉ IP của DNS server là 210.245.0.11 thì edit trong file /etc/resolv.conf :
domain cotech.com.vn
nameserver 210.245.0.11
Để kiểm tra hoạt động của DNS, ta dùng lệnh host hoặc nslookup
Code:
[root@cotech ~]# nslookup mail.kvs.org.vn
Server:         210.245.0.11
Address:        210.245.0.11#53
Non-authoritative answer:
Name:   mail.kvs.org.vn
Address: 210.245.10.69
Configure file sendmail.mc
Edit dòng sau :
dnl define(`SMART_HOST',`smtp.your.provider') thành
dnl define(`SMART_HOST',`cotech.kvs.org.vn')

Configure file /etc/hosts
File /etc/hosts được sử dụng bởi DNS client, muốn mail server (cotech.kvs.org.vn) lắng nghe ở địa chỉ 10.15.99.97 ta cần khai báo như sau trong file /etc/hosts
Code:
10.15.99.97     cotech.kvs.org.vn       cotech
Sau khi configure các file cấu hình, chạy script makefile.sh sau để biên dịch lại các file
Code:
#!/bin/bash
cd /etc/mail
make
newaliases
/etc/init.d/sendmail restart
III. Test

Từ màn hình console dùng lệnh : 
mail mail_address
subject: test
Nội dung: test successful

Nhấn ctrl + D nếu muốn add CC

1 số tùy chỉnh thêm bạn xem trong link sau:
http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch21_:_Configuring_Linux_Mail_Servers

Related Posts:

  • Debugging PHP Scripts Using slow_log and more If you are an old PHP programmer, you must have used PHP’s error_log function sometime. But PHP itself does not provide a way to find out slowly executing scripts. Slow scripts are not the ones whi… Read More
  • Log rotate Log files are the most valuable tools available for Linux system security. The logrotate program is used to provide the administrator with an up-to-date record of events taking place on the system. The logrota… Read More
  • Compile httpd 2.4.6 - P 5 Introduction to PCRE The PCRE package contains Perl Compatible Regular Expression libraries. These are useful for implementing regular expression pattern matching using the same syntax and semantics as&… Read More
  • Compile httpd 2.4.6-P1 Introduction to Apache HTTPD The Apache HTTPD package contains an open-source HTTP server. It is useful for creating local intranet web sites or running huge web serving operations. This package is known to buil… Read More
  • Compiling Software With Debian LinuxThere is a lot of free software out there that is written for Linux/UNIX that's only available in source code format. As explained on the Basics page, this is the most efficient way for the developers to distribute … Read More