Jump to content

sending email via CLI with attachment [solved]


Recommended Posts

I want to put it as cron job, run the command on a particular time, attaching a certain file...

.

I tried mutt but I dont know how to do it on a single command then run by cron..

.

any tips?

:unsure:

 

[moved from Software by spinynorman]

Edited by aioshin
Link to comment
Share on other sites

mailx -s "my subject" -F /path/to/file.name me@email.address

 

if you want to add some plain text .. try this

 

sh /command/that/outputs/text | /bin/mailx -s "Subject" -F file.name me@email.address

or

echo "Here is some plain text" | /bin/mailx -s "Subject" -F file.name me@email.address

Link to comment
Share on other sites

mailx -s "my subject" -F /path/to/file.name me@email.address

 

if you want to add some plain text .. try this

 

sh /command/that/outputs/text | /bin/mailx -s "Subject" -F file.name me@email.address

or

echo "Here is some plain text" | /bin/mailx -s "Subject" -F file.name me@email.address

thanks paul... but when I follow the above commands, this is what I get...

[root@fileserver ~]# mailx -s "see attached file" -F testfile.tar.gz aioshin@yahoo.com

-bash: mailx: command not found

.

[root@fileserver ~]# slocate mailx

/usr/share/man/man1p/mailx.1p.gz

.

[root@fileserver ~]# rpm -qal | grep mailx

/usr/share/man/man1p/mailx.1p.gz

that was invoke on my Centos box...

.

I also tried it on Mandriva

[ken@nixbox ~]$ mailx

bash: mailx: command not found

[ken@nixbox ~]$ man mailx

No manual entry for mailx

[ken@nixbox ~]$ slocate mailx

/usr/share/mailx

/usr/share/mailx/mail.tildehelp

/usr/share/mailx/mail.help

[ken@nixbox ~]$

I tried to query info at mandriva MCC and the description of mailx is..

Name: mailx

Version: 8.1.1-24mdk

Size: 89 KB

.

Summary: The /bin/mail program, which is used to send mail via shell scripts.

.

Description: The mailx package installs the /bin/mail program, which is used to send quick email messages (i.e., without opening up a full-featured mail user agent). Mail is often used in shell scripts.

.

You should install mailx because of its quick email sending ability, which is especially useful if you're planning on writing any shell scripts.

.

Files:

‎/bin/mail

‎/etc/mail.rc

‎/usr/bin/Mail

‎/usr/share/mailx

‎/usr/share/mailx/mail.help

‎/usr/share/mailx/mail.tildehelp

‎/usr/share/man/man1/Mail.1.bz2

‎/usr/share/man/man1/mail.1.bz2

so I should have to use "/bin/mail instead of mailx, but mail does'nt have an attache option..

.

any idea?

.

TIA

Edited by aioshin
Link to comment
Share on other sites

If you install nail (not mailx) you will have a mailx command:

Description :

Nail is derived from Berkeley Mail and is intended to provide the

functionality of the POSIX.2 mailx command with additional support

for MIME messages, UTF-8, POP3/POP3s and SMTP. You can also manually

set the From: address

 

but it will be /usr/bin/mailx

Edited by Steve Scrimpshire
Link to comment
Share on other sites

@steve

.

thanks for the info, I honestly, I did'nt know of that.. so I installed nail on Mandriva, but it does not have a mailx command, instead, it still uses nail...

.

@paul

thanks, the command works

echo "test" | nail -s test -a file-to-be-attached.tar.gz aioshin@yahoo.com

.

ok, I have'nt installed nail on my Centos since when I tried to do a yum list, it did'nt find anything on "nail" that will do the same job... but on other forum, I found email, a command line email client that can attach any file similar to nail... the website.. http://email.cleancode.org/?pid=download

.

just have to edit a little the /etc/email/email.conf, then

[root@fileserver ~]# email -s "test" -b -f user-sending -q -a file-2-attach.tar.gz aioshin@yahoo.com

Sending "test" |*******************************************************************************

******| 100% of 54 KB

E-Mail Sent

or with a -q to supress the sending status

.

anyway, its now solved.

.

my reason of doing this is to backup some files and email it to a certain address.

.

Thank you! :thanks:

Edited by aioshin
Link to comment
Share on other sites

:screwy: me... I overlooked everything, while I can just also do the command

echo "this is a test" | mutt -a file-2-attached.tar.gz email-me@domain.tld -s test

since I have mutt already installed.

.

but anyway, its cool, I just learned 3 CLI based email clients that can attach file...

:thumbs:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...