digg_de's picture

Hi,

sorry for the question. I found many topics in the forum about SMTP related things, but i am still confused.

I only want config a generall SMTP setting for all emails and a forwarding of all internal emails. I dont need a complete eMail-Server and i dont need to receive emails within the turnkey linux.

Here are two typical issues that i need to work:
- forwarding all emails for root@localhost and all other users to xxx@xxx.com
- use option like --mailto xxx@xxx.com from logwatch

What i need to install and how to set-up it?

Thank for help.

Forum: 
Tags: 
Jeremy Davis's picture

TurnKey is set up so that it doesn't need a separate/external SMTP server. However if that's how you want it to work then you can (see last line of this post)...

With regards to the specific issues you mention:

The first ("forwarding all emails for root@localhost and all other users to xxx@xxx.com") can be achieved by configuring an email alias for root (and each additional user). There is a thread about that here.

I think that the last post I did there (which shows how to test that the alias is working) might be the answer to your second query...?

If so then you don't need to install anything! :) Otherwise it's perhaps worthy of note that TurnKey has Postfix preinstalled and configured to send mails out...

If you actually do want to forward to a separate SMTP then have a look at this thread.

digg_de's picture

Hi Jeremy,

thanks for your really fast answer!!! I don't understand this: "TurnKey is set up so that it doesn't need a separate/external SMTP server." But if i try "sendmail recipient@example.com < email.txt", i got an error "Undelivered Mail Returned to Sender".

So why?

Thanks

PS: i don't have a real hostname on my turnkey linux.

Jeremy Davis's picture

I'm glad that you're happy to have a quick response, but TBH it's all luck of the draw. I'm sure that there are plenty of people who posted days ago that aren't quite so excited about getting their reply today...! :)

In response to your question are you sending the the address verbatim? (i.e. recipient@example.com) or are you swapping that for a real email address? I recommend that you try sending yourself an email and see what happens then... (example.com is not a legitimate domain - it is reserved purely as an 'example' domain!)

It still may not get through but then you can troubleshoot that... The returned/bounced email might be of some value (IIRC mail should be found in /var/mail/root). Also logs would probably be good to consult. IIRC they are /var/log/mail

digg_de's picture

Hi Jeremy,

yes, i used a really email-adress instead of recipient@example.com. Here is the returned email, with some error messages. I dont know, what is going wrong. (I replaced the really email-adress with xxx@xxx.com).

--469CD8226B.1423200154/localhost--

From MAILER-DAEMON  Fri Feb  6 09:41:35 2015
Return-Path: <>
X-Original-To: root@localhost
Delivered-To: root@localhost
Received: by localhost (Postfix)
 id 738FD8244A; Fri,  6 Feb 2015 09:41:35 +0100 (CET)
Date: Fri,  6 Feb 2015 09:41:35 +0100 (CET)
From: MAILER-DAEMON@localhost (Mail Delivery System)
Subject: Undelivered Mail Returned to Sender
To: root@localhost
Auto-Submitted: auto-replied
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
 boundary="0349982449.1423212095/localhost"
Message-Id: <20150206084135.738FD8244A@localhost>

This is a MIME-encapsulated message.

--0349982449.1423212095/localhost
Content-Description: Notification
Content-Type: text/plain; charset=us-ascii

This is the mail system at host localhost.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to postmaster.

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                   The mail system

<xxx@xxx.com>: host mx00.kundenserver.de[212.227.15.134] refused to
    talk to me: 501 Syntax error in parameters or arguments

--0349982449.1423212095/localhost
Content-Description: Delivery report
Content-Type: message/delivery-status

Reporting-MTA: dns; localhost
X-Postfix-Queue-ID: 0349982449
X-Postfix-Sender: rfc822; root@localhost
Arrival-Date: Fri,  6 Feb 2015 09:41:15 +0100 (CET)

Final-Recipient: rfc822; xxx@xxx.com
Action: failed
Status: 5.0.0
Remote-MTA: dns; mx00.kundenserver.de
Diagnostic-Code: smtp; 501 Syntax error in parameters or arguments

--0349982449.1423212095/localhost
Content-Description: Undelivered Message
Content-Type: message/rfc822

Return-Path: <root@localhost>
Received: by localhost (Postfix, from userid 0)
 id 0349982449; Fri,  6 Feb 2015 09:41:15 +0100 (CET)
Message-Id: <20150206084116.0349982449@localhost>
Date: Fri,  6 Feb 2015 09:41:15 +0100 (CET)
From: root@localhost (root)

test

--0349982449.1423212095/localhost--

 

Jeremy Davis's picture

So perhaps I've just been lucky in my experience of it consistently just working...

After a bit of a google it seems that a possible cause of your 501 error is that the mailserver that you are trying to send to is refusing your connection because your server isn't identifying itself with a proper FQDN. Although the info that I found was a bit sparse and certainly not conclusive.

The bit of the error that makes me think that is that your MTA (mail transfer agent) identifies itself as:

Reporting-MTA: dns; localhost

If that's the case then perhaps configuring your postfix to rely through an external SMTP would be an easier option?

I'm sure when I set mine up I didn't have a proper FQDN. ALthough now I think of it I did have a local/internal domain so my machine did actually have a FQDN although it wouldn't have been resolvable via public DNS. Beyomd that I'm sure that I just set my google apps account as a mail alias and it just worked..., although it was ages ago, so perhaps I did set up an SMTP relay through gmail...?!

If you keep in mind that TurnKey is built on Debian (v13 = Debian Wheezy aka Debian 7) and that it uses many standard Debian components (such as Postfix for handling email) then google should return plenty of info (beyond the links and info in those links I posted above).

Robert Chadwick's picture

I was about to post a question asking the exact same thing. I seem to have the same problem. However, looking at my main email server, I can see that it is rejecting 'root@localhost'. Is there a way to get postfix to send from a real email address, like root@localhost.com? I played with the settings in Webmin for an hour, and the best I could get it to do is send mail from, AND to a single email address. I also read somewhere that Postfix was tied to localhost for security. I also read that it should just work out of the box. I would just go off somewhere and read generic Debian or Postfix documentation, but that probably won't tell me how TKL is configured out of the box, and I really hate reinventing the wheel.

So, does anyone know how to configure TKL's Postfix, preferably using Webmin, to just send email out into the wild (Internet)?

Jeremy Davis's picture

But I have it working (root@localhost forwarding to my google apps email account) and as I said I'm sure that it was straight forward to configure. However it was a while ago...

And although I haven't ever used Postfix directly to send mails (other than testing the root alias I set up) I have used many of the other appliances to send mail from within whatever web app is installed and it works fine for me OOTB (pretty much all the appliances that include apps that can send mail are configured to send mail via postfix).

One of the most common causes of emails not being sent is being blocked by your ISP (if you are running as a local VM - or on local hardware). If running on Amazon (or some other popular hosting platform) a really common cause is being spam blacklisted.

When I get time later in the week I will try to redo my setup from scratch and see what happens..

Robert Chadwick's picture

Thanks for the response Jeremy. From my experience, I have been able to send emails from my home email server successfully for over a decade. Thankfully, I've only been blocked once, and it was back when I was green, and a spammer was using my server. However, my email server chokes when it tries to receive an email from an invalid address, like root@localhost. I tried sending it to my backup Yahoo address, and it also was not received (Although I'm not 100% sure of the reason, I strongly suspect it's the same). I have the same problem with a Dell server remote management card that also likes to send emails from something like root@abcdef, with no .COM, or .ORG. There might be mail servers that will accept an email from an invalid address, but I'm not lucky enough to have or know of one. It was rumored my email server was going to add that ability as an option, but it doesn't look like it was implemented. I wouldn't want to enable it anyway, as it would likely increase spam. It's rare that a legitimate email would come from an address you can't reply to. (I'm not talking about something like dontreply@somedomain.com, which I COULD reply to, but an invalid address I can't reply to)

There might be other issues here, but I can guarantee you that root@localhost is a problem for me.

 

So, is there any way to send email from a legitimate address, instead of root@localhost?

 

Thanks again!

 

RChadwick's picture

OK, I figured it out. It wasn't very intuitive :)

 

I selected the option 'Edit Config Files' in Webmin.

Then, I added the line:

myhostname = hostname.mydomain.com

It's important to put 'hostname' in front of your domain name.

When this is done, mail will be sent as root@mydomain.com or (whatever the linux user is)@mydomain.com

After I did this, I noticed in the Webmin config for Postfix, under General Options:

INTERNET HOSTNAME OF THIS MAIL SYSTEM  - The box was checked, and in the box was hostname.mydomain.com. I'm guessing it can be configured this way as well, I just wanted to tell both ways in case someone had problems.

 

My next problem was an error message after each sent message in the mail queue (Which I can't remember right now), and adding the following line got rid of it:

inet_protocols = ipv4

(I'm not using ipv6)

Now, I get the error that the connection timed out. It might be one of the many things I tried changing that broke things, or maybe just another pre-existing hurdle. Not sure.

 

Getting closer I suppose.

RChadwick's picture

OK, I found my final problem. I made a mistake. Seems long ago I configured my email server to send email through my ISP. I forwarded Postfix to my email server, and all seems to be working.

 

One final issue... Is it possible for Wordpress to send email from a specific user? Right now, all email that is sent by anything on TKL comes from a specific domain I configured, and the user (root for instance). I host a number of websites. It would be great if I could get email sent from Website-a to come from admin@website-a.com, Website-b to come from webmin@website-b.com, etc...

 

Jeremy Davis's picture

Glad you got it all sorted in the end and thanks for posting your fix. I'm sure some of the details will be useful for others. :)

digg_de's picture

Hi RChadwick,

please can you send more details. Which config file do you edit? What hostname i should added. My turnkey dont use a real domainname. How can i config an external Mailserver (like Google Mail) by using postfix.

Thanks!

Robert Chadwick's picture

Wish I could help more. My config seems a bit different than yours. I can tell you what I did, that might help you.

 

To get Postfix to forward mail to another server, I added the line to main.cf:

relayhost = 192.168.2.5  

The 192.168.2.5 was the IP address of my internal mail server. You can try and change this to google.com, or whatever name or IP address your mail server would be.

If you want to edit the file through webmin, just go to Postfix, the click 'Edit Config Files'

I'm guessing your Email server would need authentication. I have no idea how to do that, but Googling for it may turn up an answer.

 

digg_de's picture

Thanks for your answer. Yes you are right, the most mail server need an authentification. I will further try to find a solution for the postfix config.

digg_de's picture

okay, i read some wikis and tried the following things. Important: you have to change "smtp.yourserver.com" with the STMP-address of your real email-server. Also replace "username",  "password" and "email@yourdomain.com" with your correct values.

At first, most of the public mail servers need an authentification. So it is necessary to install the authentification modules:

apt-get install libsasl2-modules

Now generate password file:

touch /etc/postfix/sasl_password

input your authentification parameter like:

smtp.mailserver.com username:password

secure password file by:

chmod 600 /etc/postfix/sasl_password

now generate password database:

postmap hash:/etc/postfix/sasl_password

Also most of the public mail servers need a correct sender. So set correct sender by using canonical file:

touch /etc/postfix/sender_canonical

input your canonicals:

root email@yourdomain.com

generate canonical database:

postmap hash:/etc/postfix/sender_canonical

now edit your /etc/postfix/main.cf and append the following lines:

relayhost = smtp.mailserver.com
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
sender_canonical_maps = hash:/etc/postfix/sender_canonical

now restart postfix by:

/etc/init.d/postfix restart

But!!! Now i can send emails, but nothing arrives and no error messages occur? In which logfile can i expect what happens? Can everybody check my changes?

Thanks

digg_de's picture

Sorry, but i dont get it working.

But I implement now a little PHP-script by using php-mime-mail-parser to open the root mailbox file and PHPMailer to forwarding the emails. This works fine and i start it from the cron hourly jobs.

eXorus's picture

Hi,

I will recommend to you to used my fork https://github.com/eXorus/php-mime-mail-parser

because a lot of issues are in this code on google and I fixed it in my fork.

 

digg_de's picture

Yeah, thanks. I will change it.

digg_de's picture

In my explanation in http://www.turnkeylinux.org/forum/support/20150206/config-outgoing-email-smtp#comment-22551 there was an error! Follow the steps as describe in the comment, but append these lines to your /etc/postfix/main.cf:

relayhost = smtp.mailserver.com:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_password
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
sender_canonical_maps = hash:/etc/postfix/sender_canonical

Config the port by :XXX after the servername. And use the correct path to the password map:

/etc/postfix/sasl_password

in stead of:

/etc/postfix/sasl_passwd

Works now fine on my Turnkey LAMP!

lostalaskan's picture

@digg_de, this was exactly right! This capability is so useful, I cannot believe it isn't a part confconsole. *hint-hint*
Jeremy Davis's picture

This functionality was added as a Confconsole - Mail Relay - plugin circa 2017! :)

digg_de's picture

in additional to use the PHP mail(), it is to necessary to config the following things:

edit /etc/php5/apache2/php.ini and/or /etc/php5/cli/php.ini and set the sendmail_path:

sendmail_path = /usr/sbin/sendmail -t -i

now add the canonical for the user www-data in /etc/postfix/sender_canonical

www-data email@yourdomain.com

generate canonical database:

postmap hash:/etc/postfix/sender_canonical

now restart postfix by:

/etc/init.d/postfix restart

Add new comment