How can I send an email from the command line?

Neil Woolford neil at neilwoolford.co.uk
Sun Feb 13 18:34:21 UTC 2005


Thanks to all the many who replied with useful information about various ways
of initiating an email from the command line.

The commands in the 'mail' family could be very useful, particularly for 
reports made
regularly as cron jobs.  However this does appear to require postfix to be 
set up 'just so'
to avoid one's ISP rejecting potential messages as likely spam, and the 
machine I want
to set this up on is 600 miles away by road in France, in the care of my 
non-geek brother.
So getting it set up might have to wait...

On the other hand, Evolution certainly works for him, and the information I 
need him to send
is his current IP address so that I can VNC to maintain his machine;  this 
means that going
through Evolution is fine as he'll be there to initiate the process himself 
(from a script, started
by a launcher on the top panel is my cunning plan).

So I was particularly interested in this response:


>On Sat, 12 Feb 2005 19:51:49 +0100, adi zebic <azebic at gmail.com> wrote:
> > On Sat, 12 Feb 2005 10:39:19 +0000, Neil Woolford
> > <neil at neilwoolford.co.uk> wrote:
>
> > > while I can find how to initiate a message from the command line
> > > ("evolution mailto:joe at soap.com"), I can't find out how to insert text
> > > into the message from the command line.
> > [...]
> > > Any suggestions?
> >
> > Did you try
>
>mailto:test at test.com?&subject=your_mail_subjectt&body=your_text

That *didn't* work for me, but this was better;

mailto:test at test.com?subject=your_mail_subjectt&body=your_text

So near, but only one of the arguments after the ? was actually passed to 
Evolution!  I could
send a message with the information inserted in the body, but only if I 
didn't set a subject...

The answer, via the Evolution list, was that the "&" character is a shell 
metacharacter and
needs to be escaped to allow it to pass to Evolution.  (Otherwise the shell 
takes over the stream).

So finally;

evolution mailto:test at test.com?subject=your_mail_subjectt\&body=your_text

is a runner!

Thanks to all who helped here.  A great demonstration of that co-operative 
Linux ethos.

Neil

PS  What I'll be using will be based on this line;

evolution mailto:neil at foo.co.uk?subject="Steve's current IP 
address"\&body="$(ifconfig | grep "inet ")"

PPS  Yes, I know I could make that grep work harder to extract just the 
numbers, and I should pass
a parameter to ifconfig so that it only returns the dialup section.  Maybe 
later tonight? 


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/05






More information about the ubuntu-users mailing list