| 최초 작성일 : 2022-03-12 | 수정일 : 2022-03-12 | 조회수 : 763 |

In this post, I would like to share how to install mail server on Mac OSX. Having mail server is important if you need to send email from your web application in local environment. To do this, we will use Postfix.
Postfix is a Mail Transport Agent (MTA), supporting LDAP, SMTP AUTH (SASL) and TLS. In this post, We will setup Postfix to run with SMTP.
No need it because Postfix already exist as pre-installed on Mac OSX. Open your terminal, make sure you can see response if you type below:
$ postfix
postfix: error: to submit mail, use the Postfix sendmail command
postfix: fatal: the postfix command is reserved for the superuserGreat, then we are going to configure it to be able for sending email.
We are going to change postfix configuration file. Run this command below:
$ sudo vi /etc/postfix/main.cfMake sure if these lines below are exist
mail_owner = _postfix
setgid_group = _postdropThen, add these lines at the end of file
# Use Gmail SMTP
relayhost = smtp.gmail.com:587
smtp_sasl_mechanism_filter = plain
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_security_level = encrypt
tls_random_source = dev:/dev/urandomFrom codes above, you can see that we use Gmail SMTP for our postfix. Next step is add our gmail's username and password.
$ sudo vim /etc/postfix/sasl_passwdand add this line
smtp.gmail.com:587 your_username@gmail.com:your_passwordThen run command below to create the hash db file for Postfix.
$ sudo postmap /etc/postfix/sasl_passwdConfigure the postfix daemon
$ sudo vi /System/Library/LaunchDaemons/org.postfix.master.plistAdd these lines before </dict>
RunAtLoad
KeepAlive
Start the postfix service
$ sudo postfix start* Note that if you make changes in postfix configuration file (/etc/postfix/main.cf), you have to run command
$ sudo postfix reloadHere is the command you need to execute to test postfix.
$ echo "Test sending email from Postfix" | mail -s "Test Postfix" youremail@domain.comIf success, you will receive email in your inbox.
If you want to see mail queues, execute this command
$ mailqIf you want to see mail log, execute this command
$ tail -f /var/log/mail.logSetting up mail server on Mac OSX can be done using pre-installed Postfix. Having mail server in local environment will give you advantage for your web application that have sending email feature.