mutt send email to variable list from file - bash

I setup mutt and msmtp to send email via my google account.
Another script have a variable status.txt output like this:
newyork#mydomain.com
paris#mydomain.com
berlin#mydomain.com
How could I send email to this list, with status.txt content as body ?
Something like this:
mutt -s 'my list' $listemail < /pathto/status.txt
Thanks!

I found that this code worked for me:
while read line
do mutt $line -s 'subject-mylist' < /pahthto/status.txt
done < /pathto/listemails.txt
thanks for all!

Related

Send email via echo command with data from variable

once a day a CSV is generated that includes a single column with several rows with names (one row for each name)
I want to send these names as an email to a certain distribution list.
This is what I have so far:
#!/bin/bash
names=`cat /list_of_names.csv`
echo "$names" | mail -s "You got mail" "email#email.com"
The problem is that the email is always empty. It is correctly delivered with the right subject line, but there is no text in it.
When I check the variable manually in the console (echo "$names") all names are listed correctly.
Why is the email empty? Does anyone have an idea?
Just in case you have problems reading the file
cat /list_of_names.csv 2>&1 | mail -s "You got mail" "email#email.com"

sendmail: passing subject from shell script

i am using a template to send an html file in the body of an email.
now what i want to do is to pass the SUBJECT of the email via command like in the shell script.
My html file looks like this:
To: test#test.com
From: noreply#test.com
Subject: subject will change
Content-Type: text/html; charset="us-ascii"
<html>
this is test email body
</html>
bash script:
email=/usr/sbin/sendmail
report=/opt/html_report.html
template=/opt/email.template
$email -t < $final_report.html
I'm not sure the program sendmail is the one you want to use here. From the sendmail man page:
Sendmail is not intended as a user interface routine; other programs provide user-friendly front ends; sendmail is used only to deliver pre-formatted messages.
You probably want to use /bin/mail like this:
$ mail -s 'insert subject here' recipient#random.com < /opt/b2bpiv/email.template
Typing man mail or mail --help should list all the command-line options you'll need.

sending text file as email with curl when text file has variable

I have a script that sends an email with curl. For example:
name="John"
curl...
I have a text file for my email template. The template will have the $name variable in it. For example:
Hello, $name. This is a test.
The curl part is fine but the problem is that it sends Hello, $name. This is a test instead of Hello, John. This is a test. I'm not sure how to do this. I've tried to search how to do it but I'm not even sure how to phrase the question. I keep turning up stuff on reading variables values from a files which isn't what I'm looking to do.
This fixed my issue:
eval message=$(cat test.txt) | echo $message| curl --netrc-file "/config/.netrc" --ssl-reqd --mail-from "<myemail#gmail.com>" --mail-rcpt "<youremail#gmail.com>" --url smtps://smtp.gmail.com:465 -T -

Unix Shell Script does not send intended email

I have a shell script like this. The purpose of this script is to tail+head out a certain amount of data from file.csv and then send it to email Bob#123.com. DataFunction seems to work fine alone however when I try to call DataFunction within the email function body. It seems it sends a empty email with the correct Title and destination. The body of the email is missing which should be the data from DataFunction. Is there a workaround for this ? Thank you in advance.
#!/bin/bash
DataFunction()
{
tail -10 /folder/"file.csv" | head -19
}
fnEmailFunction()
{
echo ${DataFunction}| mail -s Title Bob#123.com
}
fnEmailFunction
You are echoing an unset variable, $DataFunction (written ${DataFunction}), not invoking the function.
You should use:
DataFunction | mail -s Title Bob#123.com
You may have been trying to use:
echo $(DataFunction) | mail -s Title Bob#123.com
but that is misguided for several reasons. The primary problem is that it converts the 10 lines of output from the DataFunction function into a single line of input to mail. If you enclosed the $(DataFunction) in double quotes, that would preserve the 'shape' of the input, but it wastes time and energy compared to running the command (function) directly as shown.
Try this:
mail -s "Title" "bob#123com" <<EOF
${DataFunction}
EOF
I tried #0xAX's answer and couldnt get it to work properly within a bash script. You simply need to save the output of DataFunction() in some variable. You can simply use these three lines to achieve this.
#!/bin/bash
VAR1=`tail -10 "/folder/file.csv" | head -19`
echo $VAR1 | mail -s Title Bob#123.com

Extra ! sign in email message body while sending mail through shell script

I am sending emails through shell script, in which I get message body from a text file. Issue comes when my disclaimer goes long, it starts getting extra ! sign in between.
Please suggest me to remove that without shortening or giving extra lines between the disclaimer. Let me know if you need any details.
Needed(say):
I am sending emails through shell script, in which I get message body from a text file. Issue comes when my disclaimer goes long, it starts getting extra ! sign in between.
Please suggest me to remove that without shortening or giving extra lines between the disclaimer. Let me know if you need any details.
Output in mail:
I am sending emails through shell script, in which I get message body from a text file. Issue comes when my disclaimer goes long, it starts getting extra ! sign in between.
Please suggest me to remove that without shortening or giving e!xtra lines between the disclaimer. Let me know if you need any details.
Here you can see that we are getting ! sign in extra word. Just keep the body long (sry I couldn't provide you the actual text), and you will get the ! sign.
Code I am using - to read from text file
EMAILMSG=$(cat $2) # $2 is path of text file
to send email
(echo -e $EMAILMSG;) | mailx -s "$SUBJECT" -b "abc#abc.com" $EMAIL -r $MAILBCC
I think this will help you to understand the situation. Please let me know anyone need further details.
I found this: Random exclamation mark in email body using CDO
It seems to indicate long lines are the problem. Try this using fold to wrap lines:
fold -s "$2" | mailx -s "$SUBJECT" -b "abc#abc.com" "$EMAIL" -r "$MAILBCC"
Style recommendations:
don't use $ALL_CAPS_VARS (here's why not)
always quote your "$vars" except when you know exactly when not to.

Resources