LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-09-2015, 11:24 AM   #1
willc86
Member
 
Registered: Dec 2014
Posts: 54

Rep: Reputation: Disabled
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!
 
Old 06-09-2015, 11:47 AM   #2
joec@home
Member
 
Registered: Sep 2009
Location: Galveston Tx
Posts: 291

Rep: Reputation: 70
Comments removed by user, see description below:

Last edited by joec@home; 06-09-2015 at 12:02 PM.
 
Old 06-09-2015, 11:54 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,133
Blog Entries: 10

Rep: Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827
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.
 
Old 06-09-2015, 12:01 PM   #4
joec@home
Member
 
Registered: Sep 2009
Location: Galveston Tx
Posts: 291

Rep: Reputation: 70
Quote:
Originally Posted by rtmistler View Post
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!
 
Old 06-09-2015, 12:08 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,133
Blog Entries: 10

Rep: Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827
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".
 
Old 06-09-2015, 12:34 PM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,133
Blog Entries: 2

Rep: Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836
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
 
Old 06-09-2015, 03:59 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,465

Rep: Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069Reputation: 2069
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write this SIMPLE SCRIPT based on output to send mail ? manalisharmabe Linux - Newbie 18 04-18-2014 12:35 AM
Script to send mail when the mail queue is more than 100 Arun Kurian Linux - Server 2 11-06-2013 10:53 AM
Creating a simple mail read only program ml41782 Linux - Newbie 8 07-18-2009 05:25 PM
Using 'mail' in a script to send mail on an alternate port? tim914 Linux - Software 4 01-16-2009 03:23 PM
CGI Script runs to send mail, but mail is never sent robertwo Linux - Newbie 2 06-10-2004 09:57 AM


All times are GMT -5. The time now is 05:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration