i am sending email and after the mail sended there is the result in console
like Mail sent sucssefully or some errors
I need to get this result to a variable
This is the command i tried
result=$(mailsend -f "alarr@ram" -t "bu@hu.du" -starttls -port "25" -auth -user "alarr" -pass "1Theant_" -smtp "smtp.hu.du" -sub "FROM router!" -M " Testing sdhit" -attach "/tmp/check_192.168.78.78")
echo "result:$result"
the mail sent but result is empty!!
Maybe
result=$(mailsend blah blah blah 2>&1)
echo "result:$result"
1 Like
appelsin:
2>&1
still emty result maybe some other numbers to try ? but i dont really rememeber those outputs numbers
mailsend puts output in console
test this:
file1=$(mktemp)
file2=$(mktemp)
mailsend -f "alarr@ram" -t "bu@hu.du" -starttls -port "25" -auth -user "alarr" -pass "1Theant_" -smtp "smtp.hu.du" -sub "FROM router!" -M " Testing sdhit" -attach "/tmp/check_192.168.78.78" > $file1 2> $file2
cat $file1
cat $file2
after that you can proceed to extract the information you want from the files ...
ncompact:
> $file1 2> $file2
i did like this
file1=$(mktemp)
file2=$(mktemp)
mailsend -f "" -t "" -starttls -port "25" -auth -user "ar" -pass "1T_" -smtp "sm" -sub "FRO!" -M " Testing sdhit" -attach "/tmp/check_192.168.78.78" > $file1 2> $file2
echo "file1: $file1 "
echo "file2: $file2 "
and result is
root@BlackAdmins:~# ./mailsendar.sh
file1: /tmp/tmp.HcEINf
file2: /tmp/tmp.efGBie
and those temp files emty
and this ...
file1=$(mktemp)
mailsend -f "alarr@ram" -t "bu@hu.du" -starttls -port "25" -auth -user "alarr" -pass "1Theant_" -smtp "smtp.hu.du" -sub "FROM router!" -M " Testing sdhit" -attach "/tmp/check_192.168.78.78" -log $file1
cat $file1
A program to send mail via SMTP from command line
1 Like
ncompact:
-log $file1
now it gets records from log and and puts it in file
26-Nov-2024 01:34:16.000: mailsend v@(#) mailsend v1.19
26-Nov-2024 01:34:16.000: Mail sent successfully
all i wanted is get result to a varible and them analise the variable
like check if the mail sent sucssefully i guess i f i wont find other way i have to use this method
do a grep on the created file and search for the string of interest and export the variable ...
file1=$(mktemp)
mailsend -f "alarr@ram" -t "bu@hu.du" -starttls -port "25" -auth -user "alarr" -pass "1Theant_" -smtp "smtp.hu.du" -sub "FROM router!" -M " Testing sdhit" -attach "/tmp/check_192.168.78.78" -log $file1
# result=1 send mail
# result=0 no send mail
result='cat $file1 | grep "Mail sent successfully" | wc -l'
echo $result
rm $file1
1 Like
result=$(mailsend blah blah blah 2>&1)
echo "result:$result"
this one actually not empty if some error accured amybe i will use this one instead
2 Likes
brada4
November 26, 2024, 1:26am
10
mailsend
echo $?
mailsend || yes oops
mailsend && yes cool
1 Like
just cheked it if a message mail is sent then it returns 0
if not 1
well thanks you too this is also the way
brada4
November 26, 2024, 7:01am
12
Thats like the original way.
1 Like
system
Closed
December 6, 2024, 7:01am
13
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.