phpmailer가 PostFix를 통해 이메일을 보낼 수 있도록 PostFix를 어떻게 구성합니까?

phpmailer가 PostFix를 통해 이메일을 보낼 수 있도록 PostFix를 어떻게 구성합니까?

CentOS에 postfix를 설정하고 smtp 인증으로 phpmailer를 구성하려고 합니다.

Php메일러작동합니다아래에 0.0.0.0/0을 넣으면마이네트워크postfix main.conf에서

mynetworks = 127.0.0.0/8, [::ffff:127.0.0.0]/104, [::1]/128, 0.0.0.0/0

하지만 이 스레드에서는 (다른 컴퓨터가 PostFix를 통해 이메일을 보낼 수 있도록 PostFix를 어떻게 구성합니까?) 누군가가 말했다스팸 문제 등을 일으킬 수 있으므로 mynetworks에 0.0.0.0/0을 입력하지 마세요.

서버를 스팸 문제로부터 보호하고 phpmailer를 작동하려면 어떻게 해야 하는지 조언을 주실 수 있나요?

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = example.com
mydomain = example.com
myorigin = /etc/mailname
inet_interfaces = all
inet_protocols = all
mydestination = localhost.localdomain localhost $mydomain
virtual_alias_maps = hash:/etc/postfix/virtual
unknown_local_recipient_reject_code = 550
mynetworks = 127.0.0.0/8, [::ffff:127.0.0.0]/104, [::1]/128, 0.0.0.0/0
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, permit
relayhost = 
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/postfix/virtual
mailbox_size_limit = 0
recipient_delimiter = +
home_mailbox = Maildir/
smtpd_use_tls = yes
#smtpd_tls_auth_only = yes
smtpd_tls_key_file  = /etc/pki/tls/private/my.key
smtpd_tls_cert_file = /etc/pki/tls/certs/my.crt
smtpd_tls_CAfile = /etc/pki/tls/certs/my.ca-bundle
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
#smtpd_tls_protocols = !SSLv2, !SSLv3
smtpd_tls_security_level = may
#SASL SMTP Authentication
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
broken_sasl_auth_clients = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_authenticated_header = yes
debug_peer_level = 2
debugger_command =
     PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
     ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.6.6/samples
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES

0.0.0.0/0을 제거하고 mynetworks = 127.0.0.0/8, [::ffff:127.0.0.0]/104, [::1]/128만 유지하면

phpmailer에서 메일을 보낼 수 없다고 합니다..

phpmailer 디버그...

2014-11-23 04:57:10 SERVER -> CLIENT: 220 myhost.com ESMTP Postfix
2014-11-23 04:57:10 CLIENT -> SERVER: EHLO www.myhost.com
2014-11-23 04:57:10 SERVER -> CLIENT: 250-myhost.com
                              250-PIPELINING
                              250-SIZE 10240000
                              250-VRFY
                              250-ETRN
                              250-STARTTLS
                              250-AUTH LOGIN PLAIN
                              250-AUTH=LOGIN PLAIN
                              250-ENHANCEDSTATUSCODES
                              250-8BITMIME
                              250 DSN
2014-11-23 04:57:10 CLIENT -> SERVER: AUTH LOGIN
2014-11-23 04:57:10 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2014-11-23 04:57:10 CLIENT -> SERVER: XXXX
2014-11-23 04:57:10 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2014-11-23 04:57:10 CLIENT -> SERVER: XXXX
2014-11-23 04:57:10 SERVER -> CLIENT: 235 2.7.0 Authentication successful
2014-11-23 04:57:10 CLIENT -> SERVER: MAIL FROM: [email protected]
2014-11-23 04:57:10 SERVER -> CLIENT: 250 2.1.0 Ok
2014-11-23 04:57:10 CLIENT -> SERVER: RCPT TO: [email protected]
2014-11-23 04:57:10 SERVER -> CLIENT: 554 5.7.1 :Relay access denied
2014-11-23 04:57:10 SMTP ERROR: RCPT TO command failed: 554 5.7.1 : Relay access denied
2014-11-23 04:57:10 CLIENT -> SERVER: QUIT
2014-11-23 04:57:10 SERVER -> CLIENT: 221 2.0.0 Bye
2014-11-23 04:57:10 SMTP Error: The following recipients failed: [email protected] Mailer Error: SMTP Error: The following recipients failed: [email protected]

및 접미사 오류 로그

myhost postfix/smtpd[8272]: connect from myhost.com[168.x.x.x]
myhost postfix/smtpd[8272]: NOQUEUE: reject: RCPT from myhost.com[168.x.x.x]: 
554 5.7.1 <[email protected]>: Relay access denied; from=<[email protected]> 
to=<[email protected]> proto=ESMTP helo=<www.myhost.com>Nov 22 23:57:10 myhost 
postfix/smtpd[8272]: disconnect from myhost.com[168.x.x.x]

PHP 메일러 설정(PHP 메일러의 색인만 변경했습니다. 다른 파일은 그대로/손대지 않음)

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>PHPMailer - SMTP email test</title>
</head>
<body>
<?php

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');

require 'PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer();
$mail->isSMTP();
$host = "myhost.com";
$username = "ara";
$password = "ara";
$Port = 25;

$mail->FromName = "Mail from gottsf3 ";
$mail->From = "[email protected]";
$mail->Host = $host;
$mail->Port = $Port;
//$mail->SMTPSecure = 'tls'; //optional 
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;


$mail->AddAddress("[email protected]");
$mail->Subject = 'gottsf3PHPMailer - SMTP email test';
$mail->Body = 'This is a plain-text message body';
$mail->SMTPDebug  = 2;

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
?>
</body>
</html>

답변1

phpmailer가 시스템의 호스트 이름이 아닌 에 연결되도록 구성해야 합니다 localhost(그러면 외부 IP 주소를 사용하여 연결됩니다).

Localhost는 postfix를 통해 메일을 릴레이할 수 있지만 mynetworks호스트 이름으로 연결하면 릴레이가 허용되지 않는 공용 IP 주소를 통해 연결됩니다.

답변2

postfix에 다음을 추가하면 문제를 해결할 수 있습니다 /etc/postfix/master.cf.

smtpd_recipient_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination

릴레이 액세스 거부는 PHPmailer에만 해당되는 것이 아닙니다. 모든 클라이언트 Outlook, Thunderbird 등에 대한 것입니다. localhost를 넣는 것은 완전한 수정이 아닌 해결 방법입니다. 예를 들어 PHPmailer/웹 서버가 postfix 이메일과 격리된 다른 서버인 경우 서버에는 localhost를 넣을 수 없습니다 ..

smtpd_recipient_restrictions에 대한 자세한 내용은 이것을 확인하십시오. https://stackoverflow.com/questions/18318789/linux-postfix-dovecot-554-relay-access-denied

관련 정보