Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the command line mail programme to attach files 1

Status
Not open for further replies.

bazil2

Technical User
Feb 15, 2010
148
DE
(Elementary user)
Under Linux I am able to send an email from the command line and I am prompted like this:

# mail some_user@some_domain.com
# Subject: Test
# Body: Test text

Is it possible to attach a file as well?

Best regards
 
Hi

Yes, is possible. But is quite much work.

Better use [tt]mutt[/tt] instead :
Code:
mutt -s [green][i]'Test'[/i][/green] -a [green][i]'attach.me'[/i][/green] [green][i]'some_user@some_domain.com'[/i][/green] [teal]<<<[/teal] [green][i]'Test text'[/i][/green]

Feherke.
 
Thank you, this worked beautifully!

To elaborate on this, I have a small web programme that allows me to choose a script and input up to 4 arguments.

I've made the following script changing the single quotes to double quotes.

Does this approach look correct; I'm very much a beginner at scripting?

#!/bin/sh
#
# Set the argument variables
Recipient=$1
Subject$2
PathToFile=$3
BodyText=$4
#
mutt -s "$2" -a "$3" "$1" <<< "$4"
 
Hi

It is correct, if we ignore the missing equal sign ( = ) at the second assignment.

But the assignments are pointless, as later you keep using the parameters, not the variables. But probably your intention was something like this :
Code:
mutt -s [green][i]"$Subject"[/i][/green] -a [green][i]"$PathToFile"[/i][/green] [green][i]"$Recipient"[/i][/green] [teal]<<<[/teal] [green][i]"$BodyText"[/i][/green]
As a note, I generally do not recommend to beginners to use Bash scripts for CGI or from SSI. There are quite many points to compromise the security.


Feherke.
 
Many thanks; you suggestions helped immensley.

Best regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top