I am running a python script in my linux PC and use 'mailx' command to send email when script fails. The command is as mentioned below,
os.system(" mailx -a 'Content-Type: text/html' -s 'Failure: Log script status' abc#domain.com def#domain.com < ../report/log_output.html")
In this case user 'abc' & 'def' gets email in his outlook client with sender as
Alert User <alertuser#x26611-testbuntu04.unassigned-domain>
(which is a dummy email).
When any of the user try to do reply all, it will send a copy to
Alert User <alertuser#x26611-testbuntu04.unassigned-domain>
as well. I dont want this to happen.
How can I write mailx command by specifying my own Reply-To email list while sending script failure email itself.
I am using below,
Distribution: Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-135-generic x86_64)
&
Edited
$ dpkg -s mailutils
Package: mailutils
Status: install ok installed
Priority: optional
Section: mail
Installed-Size: 1674
Maintainer: Ubuntu Developers <ubuntu-devel-discuss#lists.ubuntu.com>
Architecture: amd64
Version: 1:2.99.98-1.1
Provides: mail-reader, mailx
If the version of mailx you are using supports adding custom headers with the -a option like you already do with -a 'Content-type: text/html' then you can just supply it a second time with the header you want; -a 'Reply-to: you#example.net'
Relying on mailx is somewhat brittle and a huge portability problem because there are multiple incompatible mailx implementations in common use.
Related
i am using command below for sending emails via curl in a linux docker container.
curl ${REPORT_SMTP_SERVER} --mail-from ${REPORT_MAIL_FROM} --mail-rcpt ${REPORT_MAIL_TO} --upload-file error.txt
This command works pretty well and emails are sent.I was wondering is there any way how to send those emails with high priority?Unfortunately did not find any flag for that in curl documentation.
Your error.txt can include something like this :
From: "User Name" <username#gmail.com>
To: "John Smith" <john#example.com>
X-Priority: 1
Subject: This is a test
Hi John,
I’m sending this mail with curl.
send_mail(){
cat << EOF | /usr/sbin/sendmail -t ${TO_LIST} -a ${file_path}/test.CSV
From: test#gmail.com
To: test#gmail.com
#Cc: $CC_LIST
Subject: test mail
Mime-Version: 1.0
Dear User,
please find the attachment.
$result
$newline
$sign
EOF
}
tried multiple options but file is not getting attached, I verified the file exist.
Any suggestions
-bash-4.2$ uname -a
Linux hostname 3.10.0 #1 date GNU/Linux
Try the sendmail command manually. The -t option is not doing what you think it does. Similarly for the -a, unless you are using a version of sendmail very different from Debian.
Usually I install msmtp as the local mailer, setup is much easier than postfix/others and it's quite capable.
With this content in /etc/msmtprc
defaults
tls_trust_file /etc/ssl/certs/ca-bundle.crt
account default
host smtp.gmail.com
port 587
tls on
auth on
user redacted#example.com
password password
from redacted#example.com
logfile /var/log/msmtp.log
aliases /etc/aliases
I am having the error:
CROND[1587]: (ec2-user) MAIL (mailed 580 bytes of output but got status 0x004e#012)
For all the cron that should send email for ec2-user
Sending with mailx works fine:
echo "TEX" | mailx -s "TEST" redacted#example.com
Any tips on debugging this issue? I can't find much information about the status code I'm getting
Answering myself, I found a way to trigger the error on a verbose way, basically you have to send a mail using sendmail:
echo "From: root \
To: ec2-user \
Subject: Hello World \
\
This is the email body" | sudo sendmail -d -t ec2-user
On the error message I'm getting there the error explanation:
sendmail: /etc/aliases: line 11: invalid address 'postmaster'
Because there where some entries created on the /etc/aliases file (probably they where already there in the ec2 image) with an structure like this:
mailer-daemon: postmaster
Since postmaster does not have any meaning for msmtp, it's throwing the error. After commenting out this lines (#) the mail is being sent normally
I am cobbling my first Linux shell command. This command runs a yum command and email results in a periodic cron bash shell job. I am OK up to the email part where I get a "No such file or dir" error on email address(!). Can someone unravel syntax and provide method that works. Can be other shell scripting language if bash is not best for this. Seem to be having trouble with multiple line commands.
#!/bin/bash
body="Some Text"
## output yum command to a work file
echo $body > /home/security_check.txt
yum --security check-update >> /home/security_check.txt
## this works!
## mail -s 'Linux Security patches required' bob#example.com < /home/security_check.txt
## this does not
mail \
-a "From: root#example.com" \
-a "MIME-Version: 1.0" \
-a "Content-Type: text/html" \
-s "Linux Security patches required" \
bob#example.com \
< /home/security_check.txt
## error message:
## From: root#example.com: No such file or directory
Take a look at this post on sending HTML email with Unix mail.
https://unix.stackexchange.com/questions/15405/how-do-i-send-html-email-using-linux-mail-command
Seems that your need for the -a flag is to send HTML mail.
Here is solution that worked for me. Requires the mailx, yum and yum-plugin-security modules. It seems that mailx behaves differently on different distributions. Comments welcome
#!/bin/bash
## script name: yum_security_patch_report.sh
## description: emails list of security patches, saved in /etc/cron.monthly so it will be sent monthly
## generate yum security report
yum --security check-update > /home/security_check.txt
## get server hostname
HOSTNAME=echo hostname
## compose subject
SUBJECT="List of Linux security patches required - for server $HOSTNAME"
## set up TO and CC
TO="bob#example.com"
CC="sue#example.com"
## get report summary from file saved, uses $(code) notation to catch as variable
SUMMARY=$(grep 'needed for security' /home/yum_security_check.txt)
RUNFROM=($"$0")
## compose body of email
MAILBODY="Find enclosed report of Linux modules that require security patches.
$SUMMARY
This report comes from server: $HOSTNAME. This script is being run from: $RUNFROM"
## send email with mailx command
echo "$MAILBODY" | mailx -v -s "$SUBJECT" -c "$CC" -a /home/security_check.txt "$TO"
I'd like to be able to detect which particular Linux flavor is installed on a computer, e.g. Ubuntu vs Fedora, via a command line command.
Some people recommend uname -a, but that only reports the kernel version.
Try the below command....
It worked for me...
cat /proc/version
Once you know that you are running Red Hat for example, you can get to the point with:
cat /etc/redhat-release
Or on Debian:
cat /etc/debian_version
or in general :
cat /etc/*-release
Also you could use the following command
cat /etc/issue
For displaying details including release and codename of the distro
lsb_release -a
You can try:
echo $(lsb_release -si)
Try hostnamectl. It lists the operating system, CPE OS Name, Kernel, Architecture, etc.