LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   creating a simple script to send mail (https://www.linuxquestions.org/questions/linux-newbie-8/creating-a-simple-script-to-send-mail-4175544914/)

willc86 06-09-2015 11:24 AM

creating a simple script to send mail
 
Hello I am creating a simple mail script (just got into the world of scripting) My goal is to pretty much test if it has been sent out successful. I know I can just check my email, but is there a way to tell the bash script

(logical thinking)
if
"mail has been sent"
echo success!
else
echo did not process
fi


this is my script now

#!/bin/bash

echo "mail is being sent"
echo "...."
echo "...."
echo "...."
echo "...."
echo "...."
mpack -s hello /disk/windex/users/wchaple/testsample.txt sample@yahoo.com
echo "...."
echo "...."
echo "...."
echo "...."
echo "...."
echo "mail has been sent out succesfully"

thank you!

joec@home 06-09-2015 11:47 AM

Comments removed by user, see description below:

rtmistler 06-09-2015 11:54 AM

Couple of things:
  1. Use [code][/code] tags to illustrate code
  2. MPack is a PHP-based malware kit produced by Russian crackers, so I don't recommend you use that
  3. Per the LQ Rules: "Posts containing information about cracking, piracy, warez, fraud or any topic that could be damaging to either LinuxQuestions.org or any third party will be immediately removed.", and this one seems close. Therefore reported and we'll let a moderator determine that
  4. Check my link for My Bash Blog (see my signature) and there are tips for BASH scripting, one of them is the option to check the return from a system call to evaluate the result.

joec@home 06-09-2015 12:01 PM

Quote:

Originally Posted by rtmistler (Post 5374688)
MPack is a PHP-based malware kit produced by Russian crackers, so I don't recommend you use that

Ooops?!?!? I do not want to be giving advice to that!

rtmistler 06-09-2015 12:08 PM

The OP seems to be new to Linux, noting that they've said they're new to scripting, and perhaps they found the first thing which worked and also perhaps the program, while having nefarious origins may also have test and/or reasonable use cases. Hence why I said let's allow a moderator to make that judgment. I know there are other ways to generate mail from the command line, such as "sendmail" or just "mail".

TobiSGD 06-09-2015 12:34 PM

While a malware name MPack exists, this is not what the OP is referring to. A different (ancient) program named mpack exists which can be used to send mails, see here:
http://linux.maruhn.com/sec/mpack.html
http://linux.die.net/man/1/mpack

suicidaleggroll 06-09-2015 03:59 PM

Code:

echo "message" | mail -s "subject" user@domain.com
if [[ $? -eq 0 ]]; then
  echo "Message sent successfully"
else
  echo "Error sending message"
fi

Note that the exit status only tells you whether or not mail was able to submit the message, it says nothing about whether it was actually delivered. A LOT of ISPs block outgoing mail on port 25 for residential customers to cut down on spam, mail's exit status won't tell you if your ISP blocked your message or not.

If your ISP does block it, you'll need to use an external smtp server to send the email. For that I've had a lot of experience with sendemail:
http://caspian.dotconf.net/menu/Software/SendEmail/

It works great, the only drawback is the login and password for the smtp server need to be stored in plain-text.


All times are GMT -5. The time now is 04:49 AM.