본문 바로가기

리눅스

우분투에서 Office 365를 통한 Postfix 릴레이 설정하는 방법

반응형

우분투에서 Office 365를 통한 Postfix 릴레이 설정하는 방법

Postfix 설치

Postfix와 메일 유틸리티를 설치

sudo apt-get update
sudo apt-get install -y postfix mailutils
$ sudo apt install postfix mailutils
...
The following additional packages will be installed:
  gsasl-common guile-3.0-libs libgc1 libgsasl7 libidn12 libltdl7 libmailutils8 libmysqlclient21 libntlm0 libpq5 mailutils-common mysql-common ssl-cert
Suggested packages:
  mailutils-mh mailutils-doc procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre postfix-lmdb postfix-sqlite sasl2-bin | dovecot-common resolvconf postfix-cdb postfix-mta-sts-resolver postfix-doc
The following NEW packages will be installed:
  gsasl-common guile-3.0-libs libgc1 libgsasl7 libidn12 libltdl7 libmailutils8 libmysqlclient21 libntlm0 libpq5 mailutils mailutils-common mysql-common postfix ssl-cert
0 upgraded, 15 newly installed, 0 to remove and 112 not upgraded.
Need to get 11.7 MB of archives.
After this operation, 71.6 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Postfix_Configuration

Postfix 설치 중

  • "Internet Site" : Postfix가 일반적인 이메일 서버처럼 동작하도록 설정.
  • FQDN : 서버의 도메인 이름 또는 postfix.sangchul.kr형태의 주소를 입력.

Office 365를 통한 Postfix 릴레이 설정

1. Postfix 설정 파일 수정

sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.backup
sudo vim /etc/postfix/main.cf
더보기

---

cat /etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 3.6 on
# fresh installs.
compatibility_level = 3.6



# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_security_level=may

smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level=may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache


smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = postfix.sangchul.kr
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, postfix.sangchul.kr, localhost.sangchul.kr, , localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

---

relayhost = [smtp.office365.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
#smtp_tls_security_level = encrypt
#smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
  • relayhost : Office 365의 SMTP 서버 (smtp.office365.com)와 포트 (587)를 설정합니다.
  • smtp_sasl_auth_enable : SASL 인증을 활성화합니다.
  • smtp_sasl_password_maps : Postfix가 사용할 인증 자격 정보를 정의한 파일 경로입니다.
  • smtp_sasl_security_options : 익명 로그인을 방지하는 설정입니다.
  • smtp_tls_security_level : TLS 암호화를 강제하는 설정입니다.
  • smtp_tls_CAfile : 인증 기관(CA) 파일 경로입니다.

2. 인증 정보 설정

인증 정보 파일을 생성하여 Office 365로 인증할 수 있도록 이메일 주소와 비밀번호를 입력합니다.

  • your-email@your-domain.com : Office 365에서 사용하는 이메일 주소
  • your-password : Office 365 계정의 비밀번호 또는 앱 비밀번호
  • 참고 : Office 365는 일반 비밀번호 대신 앱 비밀번호를 요구할 수 있습니다. 이를 생성하려면 Office 365 계정에서 2단계 인증을 설정하고 앱 비밀번호를 생성합니다.
sudo vim /etc/postfix/sasl_passwd
[smtp.office365.com]:587 your-email@your-domain.com:your-password

3. 파일 권한 설정 및 해시 맵 생성

인증 정보를 저장한 파일에 적절한 권한을 설정하고 Postfix에서 사용할 수 있는 해시 맵을 생성합니다.

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

4. Postfix의 발신 이메일 주소 생성

Postfix가 메일을 root@postfix.localhost가 아닌 Office 365 계정 이메일 주소를 사용하여 발신하도록 설정합니다.

 

canonical 매핑을 설정해 발신자 주소를 변경할 수 있습니다.

sudo vim /etc/postfix/main.cf
smtp_generic_maps = hash:/etc/postfix/generic

매핑 파일을 설정합니다.

  • your-email@your-domain.com : Office 365에서 허용된 이메일 주소로 변경합니다.
sudo vim /etc/postfix/generic
root@postfix.sangchul.kr   your-email@your-domain.com
sudo postmap /etc/postfix/generic

5. Postfix 재시작

Postfix 설정을 적용하려면 Postfix 서비스를 재시작합니다.

sudo systemctl restart postfix

6. 방화벽 설정(필요한 경우)

SMTP 트래픽을 허용하려면 포트 587을 방화벽에서 열어야 할 수 있습니다.

sudo ufw allow 587/tcp

테스트 메일 발송

Postfix를 통해 Office 365로 메일을 보낼 수 있는지 테스트합니다.

  • recipient@example.com : 수신자의 이메일 주소를 입력합니다.
echo "테스트 이메일 내용" | mail -s "테스트 제목" recipient@example.com

로그 확인

Postfix에서 메일이 정상적으로 전송되었는지 확인하려면 로그 파일을 확인합니다.

  • 이 로그에서 메일이 성공적으로 전송되었는지 또는 오류가 발생했는지 확인할 수 있습니다.
sudo tail -f /var/log/mail.log

추가 보안 설정(선택 사항)

SPF 설정

Office 365 SMTP 서버를 통해 메일을 릴레이할 때 도메인에 대해 SPF 레코드를 추가하여 메일 서버를 신뢰할 수 있도록 구성해야 합니다.

 

Office 365에서 제공하는 SPF 레코드를 설정하는 방법입니다.

v=spf1 include:spf.protection.outlook.com -all

DKIM 설정

도메인의 DKIM 설정을 통해 메일의 인증과 무결성을 보장할 수 있습니다. DKIM 설정은 Office 365의 관리자 포털에서 관리할 수 있습니다.

DMARC 설정

도메인에 대해 DMARC 정책을 설정하여 메일 전송에 대한 보안을 강화할 수 있습니다.

 

Postfix가 Office 365를 통해 올바른 발신자 주소로 이메일을 보내도록 구성되었습니다.

 

728x90
반응형