• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question how to set up postfix to relay for a single subscription

Danny325

Basic Pleskian
Hi im using postfix for sending and recieving mails on my sites.

My new client like to send a lot of emails so even newsletter, because of that i told him to take the mail service on the domain hoster for some bucks.

Now the problem is how can i relay those outgoing emails for a single subscription. The main.cf works globally for all subscriptions and there i still need my settings for the other sites.

I already tried to send mails with phpmailer, but there seem to be timeouts and i do read phpmailer isnt able to sent second mail because of greylisting feature some mail servers have.

What reduced server load can i expect if he sends a newsletter to 1000 people for example using relaying and external smtp instead of own postfix ?
 
When an external SMTP server is involved, you normally don't use your local server at all. Instead, messages are transferred "directly" via port 25 to that external server. There will only be the load to render the mail and transmit the mail from the script to the external SMTP server. The minimum load possible.

I do not understand the rest of the question, specificially why any changes to main.cf should be required??? As you are not using anything local, you will not need to change anything on the local machine.
 
Hi Peter and thanks for your answer,
the problem sometimes i get a timeout, if i could manage to let postfix send the mail it could run in the background through the queue, instead sending direct from the page.

For example someone is using the register form, at the end of the script im sending the email. If the phpmailer is running into problems the page answers with a timeout and isnt able to send the mail. I think the external smtp is declining i dont know, but overall it could be a big problem if this happens more often.

My phpmailer settings:
PHP:
$mail = new PHPMailer(true);
    try {
        $mail->CharSet    = 'UTF-8';
        $mail->SMTPDebug = 0;                             
        $mail->isSMTP();                                    
        $mail->Host       = 'smtps.aruba.it;smtp.aruba.it';
        $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
        $mail->Username   = '[email protected]';                     // SMTP username
        $mail->Password   = 'xxx';                               // SMTP password
        $mail->SMTPSecure = 'tls';                                  // Enable TLS encryption, `ssl` also accepted
        $mail->Port       = 587;                                    // TCP port to connect to
 
        $mail->setFrom($from, $fromuser);
        $mail->addAddress($recipient, $recipientuser);     // Add a recipient
        $mail->addReplyTo($replyto, $replytouser);
 
    if(!empty($attachment)){
        $mail->addAttachment($attachment);         // Add attachments
    }
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = $subject;
        $mail->Body    = $body;
        $mail->AltBody = $bodyplain;
 
        $mail->send();
    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }

Edit:
If i could set up the main.cf for relaying only. Postfix would save the mails in the queue and send asynchron witouth phpmailer and inside of the php script.

There would be several reasons it would be better.
If the external smtp declines, external smtp is under heavy load, have currently problems, may greylisting reciever host (not sure if external smtp would handle that).

Edit2:
Maybe i shouldnt take "smtps" as first host to reduce those problems ?
 
Last edited:
I think what you are looking for could be achieved using postfix with these steps:

1) Create a file /etc/postfix/transport with this content:
<domain to relay> smtp:<relay host name>
for example
example.com smtp:externalhost.com
More details can be found here: Postfix manual - transport(5)

2) Create the map:
# postmap /etc/postfix/transport

3) Add this line to main.cf:
transport_maps = hash:/etc/postfix/transport

4) Reload Postfix service
# service postfix restart

Not tested, just a theoretical solution. Plesk does not overwrite the postfix configuration file on configuration changes, so changes are persistent.
 
It doesn't really matter much. Sure the load will go up, because now your own service will work its way through the queue several times in worst cases, but that's not really a high load.
 
Back
Top