2018. 5. 14. 13:29

CentOS 에서 Postfix 메일 보내기.

1. 우선 yum 을 이용해서 postfix 를 설치


yum -y install postfix



2. 설치 완료후 설청파일 수정


vi /etc/postfix/main.cf


3. 아래와 같이 수정.


# 호스트명 설정

myhostname = mail.나의도메인.com


# 도메인명 설정

mydomain = 나의도메인.com


# 메일발송시 FROM 부분 설정

myorigin = $mydomain


# 메일을 수신할 네트워크 지정

# localhost로 지정하면.. 외부에서 보내는 메일을 받지 못함.

net_interfaces = all

#inet_interfaces = $myhostname

#inet_interfaces = $myhostname, localhost

#inet_interfaces = localhost


# 메일서버가 최종 수신처가 되는 메일수신 도메인 설정

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain


# 신뢰하는 네트워크 지정 - 서버가 한대이므로.. 자신만 믿도록 하자

mynetworks_style = host


# 릴레이할 도메인 지정 - 위에서 설정한 수신도메인으로 지정

relay_domains = $mydestination




4. 기본 Sendmail 이 있으면 Sendmail 을 중지하고 postfix 메일서버로 지정합니다.


[root@www mail]# chkconfig --del sendmail

[root@www mail]# chkconfig sendmail off

[root@www mail]# chkconfig --list sendmail

sendmail        0:off   1:off   2:off   3:off   4:off   5:off   6:off

[root@www mail]# alternatives --config mta


There are 2 programs which provide 'mta'.


  Selection    Command

-----------------------------------------------

*+ 1           /usr/sbin/sendmail.sendmail

   2           /usr/sbin/sendmail.postfix


Enter to keep the current selection[+], or type selection number: 2

[root@www mail]# alternatives --config mta


There are 2 programs which provide 'mta'.


  Selection    Command

-----------------------------------------------

*  1           /usr/sbin/sendmail.sendmail

 + 2           /usr/sbin/sendmail.postfix


Enter to keep the current selection[+], or type selection number:


[root@www mail]# chkconfig postfix on

[root@www mail]# chkconfig --list postfix

postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off



-- 위 내용에서 빠진내용.

sendmail 중지 진행 해야 합니다.


[root@www ~]# /etc/rc.d/init.d/sendmail stop

sm-client을 종료하고 있습니다:                             [  OK  ]

sendmail 종료 중:                                          [  OK  ]



5. 25번 포트 리스닝 상태 체크

[root@www mail]# /etc/init.d/postfix start

Starting postfix:                                          [  OK  ]

[root@www mail]# netstat -an|grep LISTEN

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN


6. 설정 완료후 smtp 정산 작동여부 체크.

[root@www ~]# telnet localhost 25

Trying 127.0.0.1...

Connected to localhost.localdomain (127.0.0.1).

Escape character is '^]'.

220 mail.나의도메인.com ESMTP Postfix

mail from:test@test.com

250 2.1.0 Ok

rcpt to:test@test.com

250 2.1.5 Ok

data

354 End data with <CR><LF>.<CR><LF>

gogogo

.

250 2.0.0 Ok: queued as C66B5488040

quit

221 2.0.0 Bye

Connection closed by foreign host.