Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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?
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
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
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) ...
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
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.
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.
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...)
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.