postfix가 smtp를 통해 릴레이될 때 from 주소를 강제로 적용

postfix가 smtp를 통해 릴레이될 때 from 주소를 강제로 적용

AWS EC2 인스턴스로부터 이메일 보고서를 받으려고 합니다. 우리는 Exchange Online(Microsoft Online Services의 일부)을 사용하고 있습니다. 저는 특별히 사용자 계정을 설정했습니다.SMTP 중계, 그리고 이 서버를 통해 메시지를 릴레이하기 위한 모든 요구 사항을 충족하도록 Postfix를 설정했습니다. 그러나 Exchange Online의 SMTP 서버는 보낸 사람 주소가 인증 주소와 정확히 일치하지 않는 한 메시지를 거부합니다(오류 메시지는 550 5.7.1 Client does not have permissions to send as this sender).

주의 깊게 구성하면 이 사용자로 서비스를 보내도록 설정할 수 있습니다. 그러나 나는 조심하는 것을 별로 좋아하지 않습니다. 오히려 postfix를 사용하여 문제를 강제하는 편이 낫습니다. 이를 수행할 수 있는 방법이 있습니까?

답변1

이것이 postfix에서 실제로 수행하는 방법입니다.

이 구성은 로컬에서 시작된 SMTP 메일 트래픽과 릴레이된 SMTP 메일 트래픽 모두에서 보낸 사람 주소를 변경합니다.

/etc/postfix/main.cf:

sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps =  regexp:/etc/postfix/sender_canonical_maps
smtp_header_checks = regexp:/etc/postfix/header_check

서버 자체에서 보낸 이메일의 봉투 주소 다시 쓰기

/etc/postfix/sender_canonical_maps:

/.+/    [email protected]

SMTP 릴레이 이메일의 주소에서 다시 쓰기

/etc/postfix/header_check:

/From:.*/ REPLACE From: [email protected]

예를 들어 모든 다기능 장치와 여러 응용 프로그램에서 사용되는 로컬 릴레이 SMTP 서버를 사용하는 경우 매우 유용합니다.

Office 365 SMTP 서버를 사용하는 경우 인증된 사용자가 보낸 이메일과 보낸 사람 주소가 다른 메일은 모두 거부됩니다. 위의 구성은 이를 방지합니다.

답변2

선택 사항일반적인테이블은 서버에서 메일이 배달(전송)될 때 적용되는 주소 매핑을 지정합니다.

이것은 반대이다표준적인서버에서 메일을 수신할 때 적용되는 매핑입니다.

(참고: 일반 및 표준 테이블을 대체하기 위해 FROM 및 TO 주소가 모두 일치합니다.)

메일이 있을 때 표준 테이블 사용서버에서 수신이미 다른 답변이 설명되어 있습니다.

메일이 전송될 때 FROM 주소를 다시 쓸 수 있습니다.서버에서 전송됨을 사용하여 smtp_generic_maps.

에 따르면접미사 문서:

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

/etc/postfix/generic:
    [email protected]      [email protected]
    @localdomain.local          [email protected]

그런 다음 다음을 수행하십시오.

sudo postmap /etc/postfix/generic
sudo /etc/init.d/postfix reload

참고자료:

답변3

업데이트: IT 친구의 조언에 따라 저는 하나의 클라우드 메일 서버를 만드는 대신 모든 서버에서 postfix를 실행하고 있습니다. 지금까지 내 솔루션은 다음과 같습니다.

/etc/postfix/main.cf

# output of hostname -f - mail from local users appears to come from here
myhostname = domU-01-02-03-04-05-06.compute-1.internal
# Local delivery - include all 127.0.0.1 aliases from /etc/hosts
mydestination = $myhostname, $mydomain, rest_of_entries_from_hosts
# Needed for address translation to work
myorigin = $mydomain

# Talking to MS Online
# :submission = port 587
relayhost = [smtp.mail.microsoftonline.com]:submission
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =   # Yes, leave empty
smtp_tls_security_level = encrypt
smtp_generic_maps = hash:/etc/postfix/generic

# Enable if you need debugging, but it does leak credentials to the log
#debug_peer_level = 2
#debug_peer_list = smtp.mail.microsoftonline.com

# Only listen on the local interfaces (not the public)
inet_interfaces = localhost

# I left out a bunch of CentOS defaults.  postconf -n is your friend.
# These are included
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

/etc/postfix/sasl_passwd

# Run postmap /etc/postfix/sasl_passwd after editing
# Also, chown root:root; chmod 600
smtp.mail.microsoftonline.com [email protected]:YourP@ssw0rd

/etc/postfix/generic

# Run postmap /etc/postfix/generic
# I've seen local mail come from either source
# output of dnsdomainname
@compute-1.internal [email protected]
# output of hostname -f
@domU-01-02-03-04-05-06.compute-1.internal [email protected]

/etc/aliases

# Run newaliases after changing
# Lot of stuff here. Mostly, just make sure the graph points to root, such as
mailer-daemon:  postmaster
postmaster:     root

# And the important part - your email or distribution group
root:           [email protected]

/etc/passwd

# Sometimes it helps to expand the name, so email comes from 'root at aws host 5'
#  rather than just 'root'
# Was
#root:x:0:0:root:/root:/bin/bash
# Is
root:x:0:0:root on aws host 5:/root:/bin/bash

내가 기뻐하는 점:

  • 많은 메일이 루트로 전송되며, 한 줄에 메일 alias을 받는 사람이 표시됩니다.
  • 로컬 사용자의 모든 메일은 에서 오는 것으로 변환되므로 [email protected]MS Online SMTP 서버를 통해 전달됩니다.
  • postfix에는 sendmail보다 훨씬 더 나은 문서가 있습니다.

내가 만족스럽지 못한 점:

  • 각 호스트와 여러 단계에 대해 사용자 정의 변경이 필요합니다. 도움을 주기 위해 bash 스크립트를 작성했습니다.
  • 이름 passwd트릭이 항상 작동하는 것은 아니며 메일이 어떤 서버에서 오는지 파악하기 어려울 수 있습니다.
  • 전송된 모든 메일은 로그에 세 가지 경고를 기록합니다.
    1. warning: smtp.mail.microsoftonline.com[65.55.171.153] offered null AUTH mechanism listAUTH(SMTP 서버는 이전 STARTTLS과 이후에 null 목록을 보냅니다 AUTH LOGIN.)
    2. certificate verification failed for smtp.mail.microsoftonline.com: num=20:unable to get local issuer certificate(인증서와 관련하여 몇 가지 구성 옵션이 있지만 인증서가 갱신되면 메일 배달이 중단되는지 확실하지 않습니다)
    3. certificate verification failed for smtp.mail.microsoftonline.com: num=27:certificate not trusted(#2와 동일)

메일 서버에 대한 강력한 의견을 공유해 주신 serverfault 커뮤니티에 감사드립니다.

답변4

@Jasper의 답변에 따라 정규식에 비해 훨씬 간단한 답변은 정적 조회를 사용하는 것입니다.

sender_canonical_maps = static:[email protected]

static항상 같은 값을 반환합니다(https://www.postfix.org/DATABASE_README.html#types)

관련 정보