LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-16-2005, 12:36 PM   #1
doctorwebbox
Member
 
Registered: Jun 2003
Location: Rotherham, South Yorkshire, England
Distribution: Debian
Posts: 117

Rep: Reputation: 15
Scripted email


Every day at work we have to email a report to our HQ. I have written a script that puts the report together automatically as a cron job but then a user has to open our email client (thunderbird), create a new message, attach the report, fill out the subject and body of the email and send it.

Does anyone know of any tools I can use to send an email, with an attachment to a certain email address as part of a bash script?
 
Old 05-16-2005, 12:52 PM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 255Reputation: 255Reputation: 255
Use mail -s or possibly sendmail.. in a cron job or however you'd like

mail -s "Your Subject" recipient@domain.com < attachment.file
 
Old 05-16-2005, 03:38 PM   #3
doctorwebbox
Member
 
Registered: Jun 2003
Location: Rotherham, South Yorkshire, England
Distribution: Debian
Posts: 117

Original Poster
Rep: Reputation: 15
Getting Closer

Thanks for replying. I had a go at that, no errors were reported but no email was received at the other end. Does mail need some setting up first. I tried reading the manual but didn't find anything useful. Do I need to tell mail which smtp server and reply to address to use or does it look for this information in a config file somewhere or shouldn't any of this matter?
 
Old 05-16-2005, 05:02 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 60
Quote:
Do I need to tell mail which smtp server and reply to address to use or does it look for this information in a config file somewhere or shouldn't any of this matter?
On my box, the mail command works without any other configuring but if you are using it in a script, you may need to use the full path like this....
/bin/mail
or
/usr/bin/mutt

With mutt, you need to include a message txt or it goes into interactive mode which you surely don't want for a cron job.
-s for the subject
-a for the attachment
message.txt is a file which you typed up before hand

mutt -s "howdy" -a mypic.jpg fred@mydomain.com < message.txt

There is another thingy called uuencode. That gets installed with the sharutils package. Here is an example of how I sent some stuff but as a tar file....

tar cf - mypic.jpg | uuencode mypic.tar | mail -s "howdy" fred@mydomain.com < message.txt
 
Old 05-17-2005, 03:04 PM   #5
doctorwebbox
Member
 
Registered: Jun 2003
Location: Rotherham, South Yorkshire, England
Distribution: Debian
Posts: 117

Original Poster
Rep: Reputation: 15
Still Struggling

Thanks for the help. I tried using mutt, again no errors but no email received. I've tried it at home and at work, both on mchines running debian. This is what I did.

I put an image file on my desktop then tried to email it to myself:

adam@gabriel:~$ su
Password:
gabriel:/home/adam# apt-get install mutt
Reading Package Lists... Done
Building Dependency Tree... Done
Suggested packages:
urlview aspell ispell mixmaster openssl ca-certificates gnutls3
Recommended packages:
mime-support
The following NEW packages will be installed:
mutt
0 upgraded, 1 newly installed, 0 to remove and 150 not upgraded.
Need to get 0B/1418kB of archives.
After unpacking 3850kB of additional disk space will be used.
Selecting previously deselected package mutt.
(Reading database ... 112529 files and directories currently installed.)
Unpacking mutt (from .../archives/mutt_1.5.9-1_i386.deb) ...
Setting up mutt (1.5.9-1) ...

gabriel:/home/adam# exit
exit
adam@gabriel:~$ cd ~/Desktop/
adam@gabriel:~/Desktop$ echo "Hello there" > message.txt
adam@gabriel:~/Desktop$ mutt -s "Hello" -a Colipso.jpg me@myemailaddress.com < message.txt
adam@gabriel:~/Desktop$



But I don't receive an email. Am I doing something wrong? I have also tried sending from home to work and vice versa but still nothing.
 
Old 05-17-2005, 03:33 PM   #6
kencaz
Senior Member
 
Registered: Mar 2005
Location: Las Vegas, NV
Distribution: Mandriva Slackware FreeBSD
Posts: 1,468

Rep: Reputation: 48
Re: Getting Closer

Quote:
Originally posted by doctorwebbox
Thanks for replying. I had a go at that, no errors were reported but no email was received at the other end. Does mail need some setting up first. I tried reading the manual but didn't find anything useful. Do I need to tell mail which smtp server and reply to address to use or does it look for this information in a config file somewhere or shouldn't any of this matter?
I use "mail" as well to send a lot of my e-mail, however, I did have to specify an SMTP server. I don't know how it would work without that information. I had to configure my "ssmtp.conf" file located in /etc/ssmtp/ Here is a sample of my configuration setup for comcast's SMTP server. Most of the file is just commented information on how to configure it. Valid options are Uncommented '#'

#
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.
#

# The person who gets all mail for userids < 500
root=postmaster

# The place where the mail goes. The actual machine name is required
# no MX records are consulted. Commonly mailhosts are named mail.domain.com
# The example will fit if you are in domain.com and your mailhub is so named.
mailhub=smtp.comcast.net

# Example for SMTP port number 2525
# mailhub=mail.your.domain:2525
# Example for SMTP port number 25 (Standard/RFC)
# mailhub=mail.your.domain
# Example for SSL encrypted connection
# mailhub=mail.your.domain:465

# Where will the mail seem to come from?
#rewriteDomain=Comcast

# The full hostname
hostname=comcast.net

# Set this to never rewrite the "From:" line (unless not given) and to
# use that address in the "from line" of the envelope.
FromLineOverride=YES

# Use SSL/TLS to send secure messages to server.

#UseTLS=YES

# Use SSL/TLS certificate to authenticate against smtp host.
#UseTLSCert=YES

# Use this RSA certificate.
#TLSCert=/etc/ssl/certs/ssmtp.pem

KC
 
Old 05-17-2005, 03:42 PM   #7
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 60
Quote:
adam@gabriel:~$
Where I'm using a domain name....
[fred@sony ~]$ or sony.mydomain.com
So the from shows up as fred@sony.mydomain.com

Even so, I had to train thunderbird to not flag it as junk.

I wonder if your ISP or some spam blocker is kicking in.
 
Old 05-17-2005, 03:44 PM   #8
benjithegreat98
Senior Member
 
Registered: Dec 2003
Location: Shelbyville, TN, USA
Distribution: Fedora Core, CentOS
Posts: 1,019

Rep: Reputation: 45
Is sendmail running (or some other mta)? I'm not 100% sure but I think you at least need sendmail running before the mail command will send something out......

On your "gabriel" computer you can check out /var/log/maillog to see if an email is successfully sent out.
 
Old 05-17-2005, 03:54 PM   #9
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 60
Quote:
Is sendmail running (or some other mta)?
I think you're absolutely correct!
I just stopped postfix and the mail didn't come through.
 
Old 05-18-2005, 10:31 AM   #10
doctorwebbox
Member
 
Registered: Jun 2003
Location: Rotherham, South Yorkshire, England
Distribution: Debian
Posts: 117

Original Poster
Rep: Reputation: 15
Mail Server

So to use these tools, do I need to be running my own mailserver?
 
Old 05-18-2005, 10:49 AM   #11
benjithegreat98
Senior Member
 
Registered: Dec 2003
Location: Shelbyville, TN, USA
Distribution: Fedora Core, CentOS
Posts: 1,019

Rep: Reputation: 45
I've never used Debian (if that is what you are using) but on a lot of distro the config for sendmail is setup to where it will send emails out without further configuration. They are usually set up to not listen on any interface except localhost so you won't get attacked without realizing it.

So you will have to run sendmail (or an alternative such as Postfix, exim, etc) to send the emails out but it does not need to be able to receive email so it won't be a potential vulnerability. If you need help getting one of those setup to only send mail, we'd be happy to help. If you've never set one up, I've heard postfix is the easiest to configure. I use sendmail and it definately has a learning curve.
 
Old 05-19-2005, 05:31 AM   #12
collen
Member
 
Registered: Jun 2003
Location: /
Distribution: Fedora/Debian
Posts: 86

Rep: Reputation: 15
Well have the same issue here.

i find it strainge that you can't send and email from the bash command line, without having a smtp server running.
software like thunderbird (and others) can, there you can supply an external smtp server.

so why can't that be done with mail or mutt ??
isn't there some other bash scripting way, or commandline program where you can specify an external smtp server ?

guess another script language might do the trick.. (php...)


Greetz

Collen..
 
Old 05-19-2005, 09:40 AM   #13
benjithegreat98
Senior Member
 
Registered: Dec 2003
Location: Shelbyville, TN, USA
Distribution: Fedora Core, CentOS
Posts: 1,019

Rep: Reputation: 45
telnet maybe

telnet somebody.com
helo benji.com
mail from:<sender@benji.com>
rcpt to:<dude@somebody.com>
data
Here is the body.
.
quit



I don't know if you can put that in a script, though. You have to wait for the server to respond before you put the next line in sometimes....... Plus that doesn't do things like check for an MX when you use a domain like somebody.com....

I think even if you use something like php, you still have to have an mta running for php webpage to send an email off.
 
  


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
What is the best way to do a scripted, cronjob, backup? Mikey_GoEagles Linux - General 3 12-02-2005 10:35 AM
Disabling Window Decoration on Scripted Programs Nodge Linux - General 1 02-15-2005 09:25 AM
Scripted Install donaldsolberg Mandriva 1 10-15-2004 09:50 AM
scripted job to send mail MidnighToker Slackware 7 02-17-2004 08:39 AM
ifconfig and dhcpcd - scripted papasasha Linux - Networking 4 03-29-2002 05:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:08 PM.

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