LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-22-2021, 07:20 AM   #1
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Rep: Reputation: Disabled
Question [mail command] cannot send message


To automatically update my computer, I made this script:
Code:
#!/bin/bash
apt-get update &> /tmp/apt-list.log
apt-get upgrade -Ryq > /tmp/apt-info.log 2> /tmp/apt-error.log
if [ $? -eq 0 ] ; then
    aptitude clean
    mail -s "[Maintenance] Update done" e@mail.com <<< "Updated"
else
    cat /tmp/apt-error.log | mail -s "[Maintenance] Update failed" e@mail.com
fi
but it returns
Code:
cannot send message: Process exited with a non-zero status
and error code is
Code:
$ echo $?
36
Any idea?
 
Old 02-22-2021, 07:34 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,677

Rep: Reputation: Disabled
1) Please provide the output of
Code:
aptitude show '~i~Pmail-transport-agent'|sed '/^Desc/Q'
update-alternatives --display mailx
2) Does sending an email from the command line work?

Last edited by shruggy; 02-22-2021 at 08:20 AM.
 
1 members found this post helpful.
Old 02-22-2021, 09:15 AM   #3
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
2) Does sending an email from the command line work?
No, it doesn't work already. The command
Code:
mail -s "[Maintenance] Update done" e@mail.com <<< "Updated"
already fails with error code 36
 
Old 02-22-2021, 09:21 AM   #4
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,677

Rep: Reputation: Disabled
So how about the first question?
 
1 members found this post helpful.
Old 02-22-2021, 11:36 AM   #5
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
So how about the first question?
Actually, I had prepared the answer and when I saw the second one was failing, I though it was more important... When I'm back on the right computer, I'll post it
 
Old 02-23-2021, 01:16 AM   #6
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
So, the command aptitude show '~i~Pmail-transport-agent'|sed '/^Desc/Q' returns
Code:
Package: ssmtp
Version: 2.64-8.1ubuntu1
State: installed
Automatically installed: no
Priority: extra
Section: universe/mail
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Uncompressed Size: 2048 
Depends: libc6 (>= 2.14), libgnutls-openssl27 (>= 3.6.11-0), debconf | debconf-2.0
Conflicts: mail-transport-agent, mail-transport-agent:i386
Replaces: mail-transport-agent, mail-transport-agent:i386
Provides: mail-transport-agent
and the command update-alternatives --display mailx returns
Code:
mailx - auto mode
  link best version is /usr/bin/mail.mailutils
  link currently points to /usr/bin/mail.mailutils
  link mailx is /usr/bin/mailx
  slave mail is /usr/bin/mail
  slave mail.1.gz is /usr/share/man/man1/mail.1.gz
  slave mailx.1.gz is /usr/share/man/man1/mailx.1.gz
/usr/bin/mail.mailutils - priority 30
  slave mail: /usr/bin/mail.mailutils
  slave mail.1.gz: /usr/share/man/man1/mail.mailutils.1.gz
  slave mailx.1.gz: /usr/share/man/man1/mail.mailutils.1.gz
The script is from a magazine from 2006, maybe some parts are outdated. Since the article is for neebies, I would expect that default configurations at that time aren't valid nowadays because there is no particular warning about the command mail usage

Last edited by thomasbb; 02-23-2021 at 01:28 AM. Reason: correction
 
Old 02-23-2021, 04:33 AM   #7
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,677

Rep: Reputation: Disabled
  1. ssmtp logs errors to /var/log/mail.log and /var/log/mail.err under the handle sSMTP. Check those files, especially the latter.

  2. Check the ssmtp configuration. The things you have to set in /etc/ssmtp/ssmtp.conf are at least mailhub, and probably also root, UseSTARTTLS or UseTLS, and TLS_CA_File or TLS_CA_Dir.

    Start with
    Code:
    sudo dpkg-reconfigure ssmtp
    This can set root, mailhub, rewriteDomain, hostname, and FromLineOverride. For other settings, you'll have to edit /etc/ssmtp/ssmtp.conf in a text editor.

Last edited by shruggy; 02-23-2021 at 04:59 AM.
 
1 members found this post helpful.
Old 02-23-2021, 08:37 AM   #8
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Obviously, the author expected the reader to do some extra homework... It's moving forward, now the file /var/log/mail.log has
Code:
date hostname sSMTP[number]: Creating SSL connection to host
date hostname sSMTP[number]: Connection lost in middle of processing
and the file /var/log/mail.err has only
Code:
date hostname sSMTP[number]: Connection lost in middle of processing
The command sendmail has the same behavior and they don't prompt for a username or a password. Once ran, neither C-d or C-c stop the command. The shortcut C-z does, but then the process needs a kill -9 afterwards.
In my /etc/ssmtp/ssmtp.conf, I didn't set the AuthUser and AuthPass variables, but if I do the same happens so I removed the lines
 
Old 02-23-2021, 11:36 AM   #9
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,677

Rep: Reputation: Disabled
The message Connection lost in middle of processing comes pretty early on, even before the SMTP connection is open. Are you sure the mailhost and the port specified in the mailhub line of ssmtp.conf are correct?

At this point, I'd start testing the connection using swaks, smtpping, openssl s_client, or the good ol' telnet. E.g.
Code:
smtpping -c1 e@mail.com
If you don't know the exact name of your SMTP server, try something like
Code:
nslookup -type=mx gmail.com
Replace gmail.com with the domain name of your mail provider. Even better, contact them and ask what server name, port and authentication protocol you should use.

Last edited by shruggy; 03-03-2021 at 05:21 AM.
 
1 members found this post helpful.
Old 02-24-2021, 06:34 AM   #10
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
The configuration I set for mailhub in ssmtp.conf is the setting I use in Thunderbird, that is an smtp name and a port: smtp.uni.org:487 (but I have no idea if this is what I'm supposed to use for the ssmtp command)

The command smtpping -c1 e@ mail.com returns:
Code:
$ smtpping -c1 e@mail.com
PING e@ mail.com ([my.ip]:25): 10316 bytes (SMTP DATA)
seq=1, connect=0.95 ms, helo=156.74 ms, mailfrom=158.15 ms, rcptto=159.61 ms, datasent=341.27 ms, quit=342.65 ms

--- my.ip SMTP ping statistics ---
1 e-mail messages transmitted
connect min/avg/max = 0.95/0.95/0.95 ms
banner min/avg/max = 154.01/154.01/154.01 ms
helo min/avg/max = 156.74/156.74/156.74 ms
mailfrom min/avg/max = 158.15/158.15/158.15 ms
rcptto min/avg/max = 159.61/159.61/159.61 ms
data min/avg/max = 160.41/160.41/160.41 ms
datasent min/avg/max = 341.27/341.27/341.27 ms
quit min/avg/max = 342.65/342.65/342.65 ms
and the command nslookup -type=mx my.uni.maildomain returns
Code:
$ nslookup -type=mx my.uni.maildomain
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
univ-cotedazur.fr	mail exchanger = 20 namedomain2.
univ-cotedazur.fr	mail exchanger = 10 namedomain1.

Authoritative answers can be found from:
Just in case, I asked the admins if the configuration in /etc/ssmtp/ssmtp.conf and /etc/ssmtp/revaliases is fine. As soon as they answer, I'll let you know
 
Old 02-24-2021, 07:33 AM   #11
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Lightbulb It probably didn't work because of a typo

Quote:
Originally Posted by shruggy View Post
Even better, contact them and ask what server name, port and authentication protocol you should use.
The configuration I was using yesterday goes just perfect today. Knowing myself, I must have made a typo somewhere...

Now script #2 in my magazine: backup of a mySql data base. If I had read it first, I would have known that mail was left to me to configure.

Thank you very much for your help

---

EDIT: in case someone falls on the same magazine...

File /etc/ssmtp/ssmtp.conf takes
Code:
root=your.email@your.uni.org # the email address that sends the message
mailhub=smtp.your.uni.org:your_port_number # port 25, 487, ...
hostname=the_hostname_of_your_PC # the name of the workstation
FromLineOverride=YES
AuthUser=your_login # the login you use to access your mailbox
AuthPass=your_password # the password you use to access your mailbox
UseSTARTTLS=YES # no idea what it is
UseTLS=Yes # no idea neither
and file /etc/ssmtp/revaliases takes
Code:
your_login:your.email@your.uni.org:smtp.your.uni.org:your_port_number # otherwise it tries to send the mail from your_login@the_hostname_of_your_PC

Last edited by thomasbb; 02-24-2021 at 07:50 AM. Reason: add info
 
Old 02-24-2021, 07:50 AM   #12
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,677

Rep: Reputation: Disabled
Quote:
Originally Posted by thomasbb View Post
smtp.uni.org:487
The port 487 is unusual, I'd rather expect 587 here instead. But ultimately, admins can assign any vacant port they wish, of course.

Last edited by shruggy; 02-24-2021 at 09:44 AM.
 
1 members found this post helpful.
Old 02-24-2021, 08:36 AM   #13
thomasbb
Member
 
Registered: Mar 2019
Location: Nice
Distribution: Xubuntu
Posts: 123

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by shruggy View Post
The port 487 is unusual, I'd rather expect 587 here instead. But ultimately, admins can assign any vacant port they will, of course.
Indeed, it's 587 in my case. The automatic email works great now
 
  


Reply

Tags
mail notification



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LAN mail clients cannot send mail (receiving mail is working) rnturn Linux - Server 2 07-22-2015 11:53 PM
Debian etch - Unable to send mail from command line or from php mail command lqforumuser Linux - Newbie 1 03-01-2009 06:56 AM
can mail command be used to send mail onto global mail servers like yahoo etc dale_chip Linux - Newbie 4 08-12-2008 08:33 AM
Postfix : mail cannot send to send outside ( can send/receive locally) bobbinsupport Linux - Networking 3 12-15-2007 10:40 PM
Cannot send mail with mail() command in PHP 4.3.4, Apache 2.0.48, Mandrake Linux 10 arcanum Linux - General 3 06-27-2004 06:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration