November 13, 2018

Send email from Linux to exchange Mailbox user the easy way.

Many of Linux programming users want to send email from linux to exchange mailbox by Linux user name instead of the full email address.

There are many options but there is a easy way to send email from linux to exchange mailbox.

Let’s get started….

First you need to install sendmail or mailx or mailq.

[root@hostname~]# yum install sendmail mailx mailq

After install successfully, go to /etc/mail/sendmail.cf and find the line # “Smart” relay host (may be null).

and add your exchange server IP address and save the file:

[root@hostname~]# vi /etc/mail/sendmail.cf

# “Smart” relay host (may be null) add an exchange server to DS as following:
DSmail.domain.local

Restart sendmail service:

[root@hostname~]# /etc/init.d/sendmail restart 

Shutting down sendmail: [FAILED]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]

[root@hostname~]#

To send mail notification by user name instead full e-mail address.

edit /etc/aliases and add line with user name and e-mail address in the end of the file:

[root@hostname~]# vi /etc/aliases 

####################Users email Address##############################

userA:                     userA@domain.com
userB:                     userB@domain.com

It’s time to test it:

[root@hostname~]# mail -s “test123” userA /dev/null

Null message body; hope that’s ok

[root@hostname~]#

Troubleshooting

You haven’t received an email to you outlook mailbox.

Run the command:

[root@hostname~]# tail -F /var/log/maillog

DSN: User unknown    # You will see this message line in the log

Fix it by deleting  /etc/mail/sendmail.cf and create new sendmail.cf:

[root@hostname~]# rm -rf /etc/mail/sendmail.cf

[root@hostname~]# cd /etc/mail/

[root@hostname~]# m4 sendmail.mc > sendmail.cf

[root@hostname~]#

About The Author

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *