[Solved] Send mail with bash -mutt/gmail/smtp

Forum rules
Before you post please read this

[Solved] Send mail with bash -mutt/gmail/smtp

Postby bulsatar on Sat Nov 09, 2013 5:49 pm

Afternoon everyone,

been trying to follow the myriad of examples for how to send a simple email from bash script. So far I have installed and tried thru the examples: mailutils, sendmail and mutt. I can't get any of them to send anything and get errors everytime. I do what the examples say: install, type this, it will work....but it doesn't.

Simplest version I have tried:
Code: Select all
#!/bin/sh

MAIL = "/usr/bin/mail"
TO = "1234567890@pm.sprint.com"
SUBJECT = "Motion detected"

echo "texter text" | $MAIL -s "$SUBJECT" $TO


and these are the errors I get after trying to run the bash from cli:
./Send_Msg.sh: 3: ./Send_Msg.sh: MAIL: not found
./Send_Msg.sh: 4: ./Send_Msg.sh: TO: not found
./Send_Msg.sh: 5: ./Send_Msg.sh: SUBJECT: not found
./Send_Msg.sh: 7: ./Send_Msg.sh: -s: not found


This is in reference to getting Motion to send an email with a pic on an event. Gave up on the pic and am just trying to get the generic email to work and send anything. Will tackle working it in with Motion part later.
Greatly appreciate any help! Think I am going to take a break for a bit and go play some bf3....
Last edited by bulsatar on Sun Nov 10, 2013 1:40 am, edited 1 time in total.
bulsatar
Level 1
Level 1
 
Posts: 47
Joined: Sun May 26, 2013 1:05 am

Linux Mint is funded by ads and donations.
 

Re: Send mail with bash

Postby cwsnyder on Sat Nov 09, 2013 6:32 pm

What is your mail server? All of the methods listed assume you have an existing mail server, which handles communications between mail servers.
LMDE Mate 64-bit, LM16 Mate 64-bit
Debian Xfce 64-bit, Xubuntu 13.10 64-bit, Xubuntu Trusty Tahr 64-bit, Antergos Xfce 64-bit, PCLinuxOS LXDE 64-bit
cwsnyder
Level 6
Level 6
 
Posts: 1039
Joined: Wed Oct 20, 2010 6:49 am
Location: Nappanee, IN, USA

Re: Send mail with bash

Postby bulsatar on Sat Nov 09, 2013 7:27 pm

what is a mail server? gmail? and how would I tell the mail thingy what my gmail server is?

**yes, I am fresh out of the womb so clarification is needed cuz I have no experience with this stuff
bulsatar
Level 1
Level 1
 
Posts: 47
Joined: Sun May 26, 2013 1:05 am

Re: Send mail with bash

Postby bulsatar on Sat Nov 09, 2013 8:53 pm

Been looking more and everything I have read says that just doing mail [-s subject] add@some.address.com should work with no configuration what so ever.

I don't need the king's castle with a gazillion choices that let you fly it like an f-22, I just need to send a simple email from a bash script....
bulsatar
Level 1
Level 1
 
Posts: 47
Joined: Sun May 26, 2013 1:05 am

Re: Send mail with bash

Postby bulsatar on Sun Nov 10, 2013 1:38 am

Tried: sendmail, sendEmail, ssmtp, mutt, mailutils, postfix...finally got it with mutt!
Here are the sources I used to setup mutt with gmail as the smtp server:
http://lifehacker.com/5574557/how-to-use-the-fast-and-powerful-mutt-email-client-with-gmail
http://stackoverflow.com/questions/17359/how-do-i-send-a-file-as-an-email-attachment-using-linux-command-line
http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionGuideBasicFeatures#Sending_SMS_at_start_of_event

For some reason that I am still way too noob to know, setting a variable to the path of the pic didn't work. However, using arguments to the bash script worked when added as an attachment (couldn't get it to work in the body of the message). So, now I can get texted the pic when I hook the script to the on_picture_save of Motion. Might even try to work up a semi-overflow control in the script if I get too much shadows sending me messages.

initial basic script that works (no flowery anything)
Code: Select all
#!/bin/sh

#Destination e-mail address
TO="1234567890@pm.sprint.com" #look up your carrier's mms address
#Subject of the e-mail
SUBJECT="Motion detected"

echo -e "test 3" | mutt -s $SUBJECT -a $1 -- $TO
bulsatar
Level 1
Level 1
 
Posts: 47
Joined: Sun May 26, 2013 1:05 am


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 1 guest