LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Sendmail: Automatically Forwarding To Another Machine In The LAN (https://www.linuxquestions.org/questions/linux-server-73/sendmail-automatically-forwarding-to-another-machine-in-the-lan-784980/)

Woodsman 01-26-2010 11:15 PM

Sendmail: Automatically Forwarding To Another Machine In The LAN
 
Howdy all,

How do I automatically forward mail to a different user on a different machine in my LAN? I have been beating my head for several hours trying to accomplish this. :scratch:

I have sendmail configured as an MTA solely to receive system mail from daemons. For my personal mail I just use KMail and POP.

I want all mail on any system in my LAN to forward mail to my office system, where my normal account can receive the messages.

Although my office machine is powered on the most often, the box is not available 24/7. So any other system that can't immediately forward mail should keep that mail queued as long as necessary.

I have no problem forwarding root's mail on each local machine to a local user account on that same machine.

I have been able to forward the mails but not the way I want. The mails get forwarded to the local /var/mail/me location rather than into the remote office machine /var/mail/me.

Adding another alias in the local /etc/mail/aliases has no effect.

Creating ~/.forward in the local user's home directory also has no effect.

Both efforts always result in the mails being forwarded to the local location rather than remote.

I can send user-to-user email to and from any machine on my LAN. There are no network problems between any machine. Basic forwarding does work, just not to a remote machine at a different account.

I won't pretend to know much about mail systems, let alone sendmail. So please assume a newbie and speak softly. :D

Thanks again.

EricTRA 01-27-2010 12:10 AM

Hello,

I'm not familiar with sendmail but I use Postfix to relay all mail on a certain server to another one, be it in the same LAN or outside of it. For example my Nagios server has Postfix configured to relay all mail (multiple destination accounts that don't even exist locally) to our GMail for Enterprises. It works without any problem. Hope that helps.

Kind regards,

Eric

Woodsman 01-27-2010 12:57 AM

Hmm. My mistake. I just discovered that I can send emails from my office machine to any other account on the LAN but not vice-versa. All other machines send the mail directly to the local /var/mail rather than the correct remote location. So my office machine is forwarding mail correctly but not the others. Odd and frustrating. :( At least the other machines are consistent. Hopefully I can find the common problem.

I diffed the /etc/mail files and all are the same on all machines. Is there something else that plays a part in this?

Quote:

I'm not familiar with sendmail but I use Postfix to relay all mail on a certain server to another one, be it in the same LAN or outside of it.
Well, okay. While I'm waiting for some sendmail genius to appear, I'll read about Postfix.

I think people who deal with mail servers are sadists. :)

EricTRA 01-27-2010 01:16 AM

Quote:

Originally Posted by Woodsman (Post 3841908)
I think people who deal with mail servers are sadists. :)

More masochists in my opinion since they only inflict pain on themselves ;)

Kind regards,

Eric

centosboy 01-27-2010 04:46 AM

Quote:

Originally Posted by Woodsman (Post 3841908)
Hmm. My mistake. I just discovered that I can send emails from my office machine to any other account on the LAN but not vice-versa. All other machines send the mail directly to the local /var/mail rather than the correct remote location. So my office machine is forwarding mail correctly but not the others. Odd and frustrating. :( At least the other machines are consistent. Hopefully I can find the common problem.

I diffed the /etc/mail files and all are the same on all machines. Is there something else that plays a part in this?


Well, okay. While I'm waiting for some sendmail genius to appear, I'll read about Postfix.

I think people who deal with mail servers are sadists. :)

Quote:

I diffed the /etc/mail files and all are the same on all machines. Is there something else that plays a part in this?
dns maybe??
from the lan machines that do not appear to work, we need to first send an email in verbose mode to your office machine....

Code:

sendmail -X log_file -v yourofficecomputeraddress

Now, paste the contents of log_file here....

Woodsman 01-27-2010 02:23 PM

Solved
 
Well, some good news!

I inadvertently caused the problem at some point while trying to learn some basics of sendmail. :) I won't pretend to know even the tip of the iceberg with sendmail. A simple config file change by me was the cause of the whole exhausting evening. :newbie:

I was burning the midnight oil scratching my head about this. I was certain something was configured improperly. I was reading this web page, particularly the section (scroll down a bit) titled The Default Routing Configuration. I suspected that something on my secondary systems was configured to convince sendmail to keep dumping mail locally. Yet because the configuration files all were the same across all machines, something in those files worked fine with my primary machine. Everything I tried last night resulted in the mails from the secondary machines dumping mail locally, but any mail sent from my primary office machine arrived at the targeted secondary machine.

I won't claim any genius here, but somehow I ended up at this page describing the configuration file called local-host-names.

I suspect any sendmail guru is smiling at this point. All of the configuration files were the same across all machines. In that file was some localization URLs (aliases) that worked for the primary machine. Yet when this same config file was copied to the other machines, caused sendmail to dump mails locally because the URLs in that config file said to do just that. That is, the name of the primary machine was in that file and acted like aliases. Thus any mail sent to that location was interpreted as being a local alias.

I emptied that file on all machines and restarted sendmail. Just like that I could send mails to the correct location again. :D

Whew!:banghead:

So back to my original post. Can I forward all mails on all secondary machines to my normal user account on my primary machine?

The short answer is yes.

In the sendmail aliases config file, add an appropriate entry similar to this:

# Who gets root's mail.
root: me@mycomputer


Save the file and be sure to run the newaliases command. Unlike with the local-host-names file, changing aliases does not require restarting the sendmail daemon.

Adding to the challenge here, I have a special account on my home theater PC (HTPC). I use that account to run the system as a limited normal user. When TV recordings complete, the system send mails to that account. The mails are important because I'm still tweaking the system and the mails help me troubleshoot various errors. I wanted emails to that account sent my normal user account too.

That was what I was trying to do yesterday when All Hell Broke Loose.

The solution is straightforward.

In the user's home directory add a "hidden" text file name .forward. In that same file add the same information as in the aliases file.

Yesterday I had tried that solution too, but that local-host-names file was thwarting my attempts to forward mail.

The HTPC is not always powered on. When powered on my primary machine might not be (recording a movie at 2AM). Fortunately, sendmail queues mails and within a few days at most, the two machines are powered on concurrently and sendmail can forward the mails. The HTPC is programmed to power down after a recording when nobody is logged on, so sendmail is not going to keep trying every four hours. The queue will remain intact on the hard drive until the next time the system is powered on. At least, that is what I am hoping as I haven't tested that feature yet.

Experience often is a harsh teacher. :)

I hope this post helps others. :)

EricTRA 01-27-2010 11:45 PM

Hey Woodsman,

Nice troubleshooting! And thanks for posting your findings, I'm sure they'll come in handy somewhere down the road.

Kind regards,

Eric


All times are GMT -5. The time now is 11:49 PM.