What do I need to forward, and only forward?

Hi everyone,

I'm running Debian Sarge and I want to create aliases for the emails sent @mydomain.net. I'm new to the mail server thing and I don't know where to start. What I know is:
* I don't want to have a POP server on my Linode, I just want that, for example, the mail sent to me@mydomain.net is redirected to info@somethingelse.com and so on for a couple of email addresses. The destination email will take care of the rest (spam filtering, POP access, and so on).

  • The email addresses I want to forward from my Linode to somewhere else are not necessarily Linux accounts.

  • I don't want my box to be insecure and allow anybody to use it to relay spam everywhere.

  • I know I have to set my MX record correctly to point on my Linode (I think I'm done here).

  • No problem installing postfix if that's what I need (I heard it's safer than sendmail and even exim).

  • I've got mySQL so I could use something like postfix-mysql is needed.

  • I'm behind a firewall with only the minimum ports opened (of course!) and I'm not sure what's supposed to be opened for relaying the mail to my Linode.

  • I'd like to send to a "blackhole" every mail for which I didn't specify a redirection (forward). I want something like:
    user1@mydomain.net -> user1@whatever.com user2@mydomain.net -> user2@whatever.com info@mydomain.net -> user1@whatever.com other -> :blackhole: (or /dev/null)
    So, could someone help me out, at least to give me a hint of what kind of setup I should try?

Thanks!

14 Replies

I really like Exim4, and as it's the default in Sarge anyway I recommend you stick with it.

I've set up pretty much exactly what you're talking about. In /etc/exim4/conf.d/router, I created a file called 160localvirtual_users containing:

virtual_users:
  debug_print = "R: virtual_users for $local_part@$domain"
  driver = redirect
  domains = +local_domains
  allow_fail
  allow_defer
  data = ${lookup{$local_part}lsearch*@{/etc/aliases-domains/$domain}}
  qualify_preserve_domain
  no_more

Suppose your domain is mydomain.com. All you have to do now is create a file /etc/aliases-domains/mydomain.com containing:

*: myreal@address.com

That'll send all mail coming in to that domain (assuming you've already told exim you'll accept mail for that domain) to your other address.

Oh, and as far as handling specific addresses, in /etc/aliases-domain/mydomain.com :

user1:    user1@otherplace.com
user2:    user2@otherplace.com
bad1:     :blackhole:
*:        catchall@otherplace.com

Should have read all your questions before starting this… :-)

In order to receive mail from the outside, your Linode will need to be able to accept new connections on port 25. When it forwards mail someplace else, it will connect to the other machine's port 25.

So your firewall rules must allow unsolicited inbound connections on port 25, and new connections to be created outgoing to port 25.

Wow thanks Xan for all the answers and the speed! I'm trying this out this evening and I'll give some news about the results. :)

Is there something else to do? It doesn't work.

Here's what I did to configure the whole thing.

4. I've installed exim4, for some reason, I still had exim3.

  1. I've added the 160localvirtual_users in /etc/exim4/conf.d/router.

  2. I've added the mydomain.com file (yes, with my own domain ;)) in the /etc/aliases-domains.

  3. Is there another line to add to the main configuration?

Here's what I did for debugging:

4. I've sent emails to a valid user: nothing. No mail-delivery error, no forward.

  1. I've sent emails to an invalid user: one of them returned a mail-delivery error after a long wait.

  2. I've connected with "telnet mail.mydomain.com 25" to test the exim4 server. I can send a mail (all the answers are correct) but I didn't received it.

  3. I've tried sending to another domain than my own and I have a message telling me I can't relay to this domain, good!

So, it seems my firewall is setup correctly, that the exim4 server is running and can receive email to relay but that it disapears in it. Maybe it is not relayed or maybe it doesn't know where to relay it (bad configuration?).

I've found a message telling me to add a line in the main configuration but I'm not sure to understand:

> * put this into /etc/exim4/conf.d/router/160localvirtual_users

  • add a "domainlist virtual_domains = …" to conf.d/main/

I feel a bit lost, I'm not sure what I should do next to pinpoint my problem. Any clues?

Thanks again for your time!

Ok, I did receive the emails in my Linux account (when I type mail) so they are not forwarded to my other@domain.net. I guess there's a problem with my config. Any clue to why it is not working?

hmm…

Did you run update-exim4.conf and restart Exim after making config file changes? That's what makes Exim 4 assimilate changes.

I can now receive mail but only if:
* The mail is forwarded to a completely different domain (I have mydomain.net (my linode) and mydomain.com (another)). When I want user@mydomain.net to be redirected to mydomain.com, I receive it in my linux account instead of on mydomain.com. Weird.

  • On my system, I have the account user1 created. I've made 2 aliases, user1@mydomain.net and admin@mydomain.net. So admin does not match any account and when I try this email, I've got a "account does not exist" return mail.
    Also, altought I did an update-exim4.conf and restarted exim, the aliases are not refreshed every time. I'm not sure to understand. :roll:

You say you've made two aliases: user1@mydomain.net and admin@mydomain.net. Just to double-check: inside the file /etc/aliases-domains/mydomain.net, they're just known as user1 and admin. So it should look like:

user1:    someplace@else.net
admin:    somewhere@else.net

Is that what you have?

I exactly have in /etc/aliases-domains/mydomain.net:

user1:      user1@elsewhere.com
admin:      user1
*:          :blackhole:

mydomain.net being my linode.

elsewhere.com is another domain.

user1 being an account on my linode.

admin is not an account.

Is that okay?

I just tried exactly that alias file, and it worked exactly as expected. I went through all the Exim config files to find the ones that I'd modified, and the only one that would remotely relate to what we're doing was 400exim4-configsystem_aliases. I'm not sure what I even changed, or if it relates, but it now reads:

system_aliases:
  debug_print = "R: system_aliases for $local_part@$domain"
  driver = redirect
  domains = +local_domains
  allow_fail
  allow_defer
  data = ${lookup{$local_part}lsearch{/etc/aliases}}
#  user = list
#  group = mail
  file_transport = address_file
# pipe_transport = address_pipe
# directory_transport = address_directory

Other than that, I'm not sure what to tell you…

I've got the same thing in 400exim4-configsystemaliases, seems to be the default configuration. And normally, if I read correctly, the email shouln't reach this file, it should be routed with our 160 file.

I'll try to find something else, I'll post it here if I'm successful.

Thanks a lot for your time Xan. It was really helpful! :)

Sorry it didn't go more smoothly… It's probably something stupid we're both overlooking.

If I think of it at 4 in the morning I'll post here. :-) And if you need to know anything more about my config, let me know.

i'm probably not going to be of too much help here, but i would like to say i just used the above mentioned virtual_users router and it worked just fine for me. and to say thanks so much for that bit of info.

since i wanted some mail to fall through and be delivered locally, i removed the no_more line at the end.

one thing i found out is that you must have a domain alias file for each delivered domain or exim gives an error and won't accept recipient for that domain:
> temporarily rejected RCPT user@the.domain : failed to open /etc/aliases-domains/the.domain for linear search: No such file or directory

one question for lpfavreau, when you configured exim4 the first time (or via dpkg-reconfigure exim4-config) did you select "Yes" for "Split configuration into small files?" if you selected No, then you would need to add Xan's bit of code somewhere inside exim4.conf.template. i had originally specified No, but later changed it to Yes with the dpkg-reconfigure command.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct