# Problems with mail relaying...

## zeveck

So, I want the e-mails generated by the likes of cron, etc., to actually send out to my Internet e-mail address.

This isn't working.  :Crying or Very sad: 

So far I have tried using mailx with ssmtp, but I get:

```
send-mail: Cannot open mail:25

Can't send mail: sendmail process failed with error code 1
```

So I tried emerge sendEmail and then using sendEmail, but it just gets:

```
sendEmail - ERROR: Connection attempt to [localhost:25] failed: Connection refused
```

I want to keep this as simple as possible. It has been suggested I need to install postfix but that looks to be an order of magnitude more complicated that what I need this for.

Also...postfix gets blocked by ssmtp...which kinda implies I should be able to do this with ssmtp...hell...I though that SENDING e-mail was point in ssmtp!?

What am I doing wrong?

----------

## adsmith

what are you using as your mail relay host?  ssmtp doesn't do local mail reciept, so you can't use it for local mail (e.g., root@localhost), just for getting mail offsite.  

Hence, if your mail recipient for cron is something like root@localhost (and you have no aliases set up, say like "root: you@somehost.com" in /etc/mail/aliases) ssmtp will complain that it can't connect to the mail server, because there isn't one running locally.

----------

## zeveck

Okay. Well, I didn't know that part of it, so thank you muchly for that.

But, I was not that far along yet...I am still having trouble getting ssmtp to send offsite. =/

What sort of thing would I have to use for local mail delivery? I've seen a wiki article on doing it with postfix, but that seems extreme.

----------

## adsmith

Well, postfix may seem "extreme" compared to ssmtp, but it is so much more flexible and powerful, so if you ever want to do anything more than shipping mail to your ISP, then you might as well use postfix.  the configuration isn't hard, the documentation is fairly good, and there's lots of people to ask about it.

anyway, as for getting mail offsite, I assume you are using your ISP's outgoing mail server as a relay?

if so, you may need (sasl) authentication and a username/password provided by your ISP.  E.g., Verizon DSL requires such authetication, but RoadRunner cable does not (in NC, USA).

----------

## zeveck

Hmmm...so I tried setting up postfix for local mail delivery as suggested at http://gentoo-wiki.com/TIP_Postfix_Setup_for_Local_Mail_Only . It seems to sorta work, in that mailx no longer complains when I try to send mail, but if I try mailx at the commandline it still says "No mail for root".  :Confused: 

...so now it seems the mail is just vanishing...  :Sad: 

----------

## adsmith

try having the mail forward to your main user, as listed in the last section of that wiki

----------

## adsmith

another problem might be the "accepted_hosts" or "accepted_domains" (or whatever they're called) settings in main.cf.    If it doesn't include the exact server name or domain in the address you feed it, mail will get lost in the ether.  

also, read the postfix logs and use mailq to figure out what's happening.

EDIT: I bothered to look up the setting names: specifically, look at mydestinations and maybe mynetworks.

----------

## zeveck

The postfix logs say things like:

```
[postfix/pickup] 2B3CA2CF87: uid=0 from=<root>

[postfix/qmgr] 2B3CA2CF87: from=<root@example.foo>, size=339, nrcpt=1 (queue active)

[postfix/local] 2B3CA2CF87: to=<user@example.foo>, orig_to=<root>, relay=local, delay=0, status=sent (delivered to maildir)

[postfix/qmgr] 2B3CA2CF87: removed
```

To the extent I understand what I should be seeing, that looks right...  :Confused: 

I am trying to use mailx to send and check the mail. Could it be that mailx doesn't work with postfix. There is no /etc/mailx.cnf 

All mailq seems to bring back is "Mail queue is empty".

Even stranger is that if I look in user's home directory there is a .maildir, and if I go into .maildir there are cur, new, and tmp, and new gets new files whenever I try to send an e-mail to user. This all implies it is working...  :Sad:  But it ain't...

----------

## zeveck

Also...how do I make Gentoo check for mail on login such that I'll get something like "You have mail!" on login?

----------

## zeveck

Hmmm...when I removed the setting for home_mailbox in main.cnf it made it so that mailx found the mail! Or...rather...just the newest message. It looks like if I set home_mailbox then the mail never gets delivered to the system mailbox, which is where mailx looks.

Does that sound right?

If so...why would you ever set home_mailbox?

Is there any way to get mailx to look in the home mailbox rather than the system mailbox?

Or is my problem that I am trying to get mailx to do things that are too complicated for it?

----------

## adsmith

oh, well then it's simple: you have postfix configured to deliver to maildir, but mailx, or whatever, is looking for a mail spool file.  fix one of the two.  Different people like mail delivered different ways.  E.g., I hat maildir and use /home/mail instead of /var/spool/mail for my spool files, for easier NFS sharing.

for the mail check, the program is mailutil, but there is a bash setting to change the interval between mail checks.

----------

## adsmith

Yes, that is right.  setting home_mailbox tells it to use maildir, not system spoolfiles.  Some people like maildir.  I don't.

to make things simple (that is, use mbox spool files instead of maildir, for now), I reccomend doing this:

comment out ALL of the delivery location options, and just set spoolfile:

```

# DELIVERY TO MAILBOX

#

# The home_mailbox parameter specifies the optional pathname of a

# mailbox file relative to a user's home directory. The default

# mailbox file is /var/spool/mail/user or /var/mail/user.  Specify

# "Maildir/" for qmail-style delivery (the / is required).

#

#home_mailbox = Mailbox

#home_mailbox = Maildir/

 

# The mail_spool_directory parameter specifies the directory where

# UNIX-style mailboxes are kept. The default setting depends on the

# system type.

#

#mail_spool_directory = /var/mail

mail_spool_directory = /var/spool/mail

```

honestly, no one ever uses mailx as a mail client, just as a dumb scriptable mail sender.  use mutt and you can tell it to get mail wherever you want and in whatever format you prefer.

----------

## zeveck

What package includes mailutil?

----------

## adsmith

hmm.. it looks like mailutil is in pine.  but this is I think independent of the bash builtin check function

----------

## zeveck

Hmmm....MAILCHECK is set to 60...and according to man bash that should mean it checks every 60 seconds...but it never actually tells me I have mail....how do I configure bash mail checking?

If I do echo $MAIL I get /var/spool/mail/user.

If I do echo $MAILCHECK I get 60.

But I do env MAIL is there but MAILCHECK is not. ??

----------

## zeveck

Erm...well...I just threw mailx at the end of .bashrc and now it at least checks when I login......though it doesn't seem to check the rest of the time.....  :Crying or Very sad: 

----------

## Trebiani

 *adsmith wrote:*   

> hmm.. it looks like mailutil is in pine.  but this is I think independent of the bash builtin check function

 

it's in the package "uw-mailutils"

----------

