setting up mailx using postmap/postfix

Apr 29, 07:25 AM

note: php-mailer has been discontinued – all mail should go through mailx (and not sendmail per john q)

Two files that contain the gmail password
  • /usr/local/lib/php/PhpMailerSecurity.php — 2016-05-10
  • /etc/postfix/sasl_passwd
==============

https://devops.profitbricks.com/tutorials/configure-a-postfix-relay-through-gmail-on-centos-7/

note comment at end:
his works well … except now you have to log into your google account and there’s an option to turn on “less secure apps” to access your account. After I clicked that the mail went through :)

1) add the following lines to the end of /etc/postfix/main.cf:
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
mailbox_size_limit = 512000000
always_bcc = edwardsmarkf@gmail.com
virtual_alias_maps = hash:/etc/postfix/virtual

vi /etc/postfix/sasl_passwd;
[smtp.gmail.com]:587 mark@comptonpeslonline.com:MaRkSPaSsWoRd

after editing the sasl_passwd file:
  • postmap /etc/postfix/sasl_passwd; # lets postfix mail know about the changes
  • postfix flush ;
  • postfix stop ;
  • postfix start ;
  • tail /var/log/maillog ;
===============

CLI example:

echo ‘PLEASE this needs to work’ | mail -r “info@comptonpeslonline.com (Marky Edwards)” -s “subject here” mark@edwardsmark.com ;

PHP example:

$to = 'mark@edwardsmark.com';
$subject = 'the subject with outgoing email anme';
$message = 'hello shithead';
$headers = 'From: MarkyBoy Edwards‘ . “rn” . ‘Reply-To: webmaster@example.com’ . “rn” . ‘X-Mailer: PHP/’ . phpversion();

mail($to, $subject, $message, $headers);

==

add to end of /etc/postfix/main.cf :
always_bcc = edwardsmarkf@gmail.com

Mark Edwards

,

---

Commenting is closed for this article.

---