error sending email via mutt/msmtp w/ cronjob (status 0x0001 from MTA#012)
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
echo "Hello this is the body message, we are sending email with attachement using mutt and msmtp" | mutt -a /home/osboxes/Downloads/"$(date '+%Y-%m-%d_%H-%M-%S').log" -s "this is the subject of the message" -- xxxx@gmail.com
However, I tried to install a cronjob to run it daily but it isn't working, this is the job:
# m h dom mon dow command
* * * * * root /home/osboxes/Downloads/sendlogzzz.sh
sudo crontab -l :
# m h dom mon dow command
* * * * * root /home/osboxes/Downloads/sendlogzzz.sh
(I intentionally set it to send every minute to see if it would work).
I looked sudo grep CRON /var/log/syslog :
Quote:
Apr 10 16:32:01 osboxes CRON[1430]: (root) MAIL (mailed 28 bytes of output but got status 0x0001 from MTA#012)
Apr 10 16:33:01 osboxes CRON[1675]: (root) CMD (root /home/osboxes/Downloads/sendlogzzz.sh)
Apr 10 16:33:02 osboxes CRON[1674]: (root) MAIL (mailed 28 bytes of output but got status 0x0001 from MTA#012)
Apr 10 16:34:01 osboxes CRON[1932]: (root) CMD (root /home/osboxes/Downloads/sendlogzzz.sh)
Apr 10 16:34:01 osboxes CRON[1931]: (root) MAIL (mailed 28 bytes of output but got status 0x0001 from MTA#012)
This is my ssmtp config:
Quote:
root=postmaster
SERVER=xxx@gmail.com
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587
"# The full hostname. Must be correctly formed, fully qualified domain name or GMail will reject connection.
hostname=yourlocalhost.yourlocaldomain.tld"
mine is:
hostname=osboxes.lan
Should I include the local IP before osboxes.lan??
msmtp: cannot log to /tmp/msmtp.log: cannot lock (tried for 10 seconds): Permission denied
msmtp: log info was: host=smtp.gmail.com tls=on auth=on user=xxx@gmail.com from=xxx@gmail.com recipients=xxx@gmail.com mailsize=669 smtpstatus=250 smtpmsg='250 2.0.0 OK 1586706197 o18sm6025147qkk.52 - gsmtp' exitcode=EX_OK
I'm really confused now. Is it msmtp or ssmtp? The config file you've shown is clearly /etc/ssmtp/ssmtp.conf. The configuration for msmtp lives in msmtprc though.
I edited the ssmtp config, but I also have msmtp installed and this is the file:
Quote:
account default
host smtp.gmail.com
port 587
logfile /tmp/msmtp.log
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
auth login
user xxx@gmail.com
password xxx
from First Last Name
account account2
This is the ssmtp config, root, SERVER, and AuthUser are all the same gmail acc:
Quote:
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=xxx@gmail.com
SERVER=xxx@gmail.com
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587
# Where will the mail seem to come from?
rewriteDomain=gmail.com
# The full hostname
hostname=osboxes.lan
# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
Debug=YES
I havne't done anything to the revaliases file for ssmtp:
Quote:
# sSMTP aliases
#
# Format: local_accountutgoing_address:mailhub
#
# Example: root:your_login@your.domain:mailhub.your.domain[ort]
# where [ort] is an optional port number that defaults to 25.
Wait, how is mutt configured to send messages? Did you set either sendmail or smtp_url in your muttrc file to some value? Or is it using the default (/usr/sbin/sendmail)? Then where does that point to? On many distributions, it's a symbolic link managed through alternatives system.
# map delete-char to a sane value
bind editor <delete> delete-char
# some people actually like these settings
#set pager_stop
#bind pager <up> previous-line
#bind pager <down> next-line
# Specifies how to sort messages in the index menu.
set sort=threads
# The behavior of this option on the Debian mutt package is
# not the original one because exim4, the default SMTP on Debian
# does not strip bcc headers so this can cause privacy problems;
# see man muttrc for more info
#unset write_bcc
# Postfix and qmail use Delivered-To for detecting loops
unset bounce_delivered
set mixmaster="mixmaster-filter"
# System-wide CA file managed by the ca-certificates package
set ssl_ca_certificates_file="/etc/ssl/certs/ca-certificates.crt"
# imitate the old search-body function
macro index \eb "<search>~b " "search in message bodies"
# simulate the old url menu
macro index,pager,attach,compose \cb "\
<enter-command> set my_pipe_decode=\$pipe_decode pipe_decode<Enter>\
<pipe-message> urlview<Enter>\
<enter-command> set pipe_decode=\$my_pipe_decode; unset my_pipe_decode<Enter>" \
"call urlview to extract URLs out of a message"
# Show documentation when pressing F1
macro generic,pager <F1> "<shell-escape> zcat /usr/share/doc/mutt/manual.txt.gz | sensible-pager<enter>" "show Mutt documentation"
# show the incoming mailboxes list (just like "mutt -y") and back when pressing "y"
macro index y "<change-folder>?<toggle-mailboxes>" "show incoming mailboxes list"
macro pager y "<exit><change-folder>?<toggle-mailboxes>" "show incoming mailboxes list"
bind browser y exit
# If Mutt is unable to determine your site's domain name correctly, you can
# set the default here. (better: fix /etc/mailname)
#
# set hostname=cs.hmc.edu
# If your sendmail supports the -B8BITMIME flag, enable the following
#
# set use_8bitmime
# Use mime.types to look up handlers for application/octet-stream. Can
# be undone with unmime_lookup.
mime_lookup application/octet-stream
# Upgrade the progress counter every 250ms, good for mutt over SSH
# see http://bugs.debian.org/537746
set time_inc=250
# Allow mutt to understand References, Cc and In-Reply-To as headers in mailto:
mailto_allow = cc in-reply-to references
##
## *** DEFAULT SETTINGS FOR THE ATTACHMENTS PATCH ***
##
##
## Please see the manual (section "attachments") for detailed
## documentation of the "attachments" command.
##
## Removing a pattern from a list removes that pattern literally. It
## does not remove any type matching the pattern.
##
## attachments +A */.*
## attachments +A image/jpeg
## unattachments +A */.*
##
## This leaves "attached" image/jpeg files on the allowed attachments
## list. It does not remove all items, as you might expect, because the
## second */.* is not a matching expression at this time.
##
## Remember: "unattachments" only undoes what "attachments" has done!
## It does not trigger any matching on actual messages.
## Qualify any MIME part with an "attachment" disposition, EXCEPT for
## text/x-vcard and application/pgp parts. (PGP parts are already known
## to mutt, and can be searched for with ~g, ~G, and ~k.)
##
## I've added x-pkcs7 to this, since it functions (for S/MIME)
## analogously to PGP signature attachments. S/MIME isn't supported
## in a stock mutt build, but we can still treat it specially here.
##
attachments +A */.*
attachments -A text/x-vcard application/pgp.*
attachments -A application/x-pkcs7-.*
## Discount all MIME parts with an "inline" disposition, unless they're
## text/plain. (Why inline a text/plain part unless it's external to the
## message flow?)
##
attachments +I text/plain
## These two lines make Mutt qualify MIME containers. (So, for example,
## a message/rfc822 forward will count as an attachment.) The first
## line is unnecessary if you already have "attach-allow */.*", of
## course. These are off by default! The MIME elements contained
## within a message/* or multipart/* are still examined, even if the
## containers themselves don't qualify.
##
#attachments +A message/.* multipart/.*
#attachments +I message/.* multipart/.*
## You probably don't really care to know about deleted attachments.
attachments -A message/external-body
attachments -I message/external-body
##
# See /usr/share/doc/mutt/README.Debian for details.
source /usr/lib/mutt/source-muttrc.d|
Is there something I need to change in /etc/Muttrc.d?
Is there something I need to change in /etc/Muttrc.d?
If there're any *.rc files beyond charset.rc, colors.rc, compressed-folders.rc, gpg.rc, and smime.rc installed by Debian mutt package then probably yes.
The config you linked above speaks to Gmail directly: with such setup a local MTA is completely unnecessary, neither msmtp nor ssmtp nor anything else. Your Muttrc though doesn't set smtp_url nor sendmail explicitly, that means it uses /usr/sbin/sendmail by default.
Please show the output of readlink -e /usr/sbin/sendmail
Also, please sanitize the syslog output from your post #5. It shows your real email address.
Further, there's this line in your ssmtp config:
Code:
SERVER=xxx@gmail.com
ssmtp doesn't know about keyword SERVER. Where did you get it from?
Quote:
Originally Posted by jorjor242
Maybe this is the issue? On the arch page it says
"# The full hostname. Must be correctly formed, fully qualified domain name or GMail will reject connection.
hostname=yourlocalhost.yourlocaldomain.tld"
mine is:
hostname=osboxes.lan
Should I include the local IP before osboxes.lan??
Yes, this may be an issue. No, you shouldn't include the IP. What is the output of commands hostname --fqdn, host $(hostname) and hostnamectl status?
If there're any *.rc files beyond charset.rc, colors.rc, compressed-folders.rc, gpg.rc, and smime.rc installed by Debian mutt package then probably yes.
The config you linked above speaks to Gmail directly: with such setup a local MTA is completely unnecessary, neither msmtp nor ssmtp nor anything else. Your Muttrc though doesn't set smtp_url nor sendmail explicitly, that means it uses /usr/sbin/sendmail by default.
Please show the output of readlink -e /usr/sbin/sendmail
Also, please sanitize the syslog output from your post #5. It shows your real email address.
Further, there's this line in your ssmtp config:
Code:
SERVER=xxx@gmail.com
ssmtp doesn't know about keyword SERVER. Where did you get it from?
Yes, this may be an issue. No, you shouldn't include the IP. What is the output of commands hostname --fqdn, host $(hostname) and hostnamectl status?
there are no more .rc files/directories fortunately!
Output:
readlink -e /usr/sbin/sendmail:
/usr/sbin/ssmtp
I don't know where I got SERVER=xxx@gmail.com from, probably a tutorial - should I delete/comment out the line?
Outputs:
hostname --fqdn
osboxes
host $(hostname)
osboxes.lan has address 192.168.1.102
hostnamectl status
Static hostname: osboxes
Icon name: computer-vm
Chassis: vm
Machine ID: xxxxx
Boot ID: xxxx
Virtualization: oracle
Operating System: Ubuntu 19.10
Kernel: Linux 5.3.0-46-generic
Architecture: x86-64
Thank you so much for helping thus far, it is very confusing getting these overlapping programs to work with info on the internet which can be contradictory...
Could it be that mutt for user osboxes configured quite differently compared to root? I mean /home/osboxes/.muttrc or /home/osboxes/.mutt/muttrc, whichever you have? Try to change the username field in crontab to that user and see if you can get mails off your system then.
I'm not sure, but it seems to me that when you're running the script from command line the mail gets relayed via msmtp. Could you please show the output of mutt -D|grep sendmail= ?
You also could try sudo apt install msmtp-mta This will force uninstalling ssmtp and make the symlink /usr/sbin/sendmail point to msmtp instead.
I also found this thread in Zimbra forum. It's pretty old and I'm not sure if it applies here, but it suggests that you may have problems sending emails to Gmail if you're on a dynamic DNS.
tail -n 50 /var/log/suricata/fast.log > "$(date '+%Y-%m-%d_%H-%M-%S').log"
echo "Hello this is the body message, we are sending email with attachement using mutt and msmtp" | mutt -a /home/osboxes/Downloads/"$(date '+%Y-%m-%d_%H-%M-%S').log" -s "this is the subject of the message" -- xxx@gmail.com
I don't have any trouble sending an email with that mutt command, it just won't work in the bash script
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.