FreeBSD send mail with attachments from command line / shell prompt

by Vivek Gite on October 3, 2007 · 4 comments

Q. I need to send few reports everyday as a mail attachment. I’m using FreeBSD 6.2 server. How do I send mail from a command line or a shell script?

A. You can easily send email attachment using mutt mail client. It works from command line or a shell prompt. However mutt is not installed by default. You need to install mutt command. mutt command also works under UNIX and Linux like commands.

Install mutt under FreeBSD

Mutt is a small but very powerful text based program for reading electronic mail under unix operating systems, including support color terminals, MIME, and a threaded sorting mode.

Use pkg_add command for installing software package distributions. Type the following command to install mutt:
# pkg_add -v -r mutt
Alternatively, you can use FreeBSD ports collections:
# cd /usr/ports/mail/mutt
# make install clean

FreeBsd command line mail attach with mutt

Send reports.tar.gz file to vivek@gmail.co.in
$ mutt -s "Reports" -a reports.tar.gz vivek@gmail.co.in
OR
$ mutt -s "Subject" -a reports.tar.gz vivek@gmail.co.in < /tmp/mail-message.txt
Where,

  • -a file : Attach a file to your message using MIME.
  • -s subject : Specify the subject of the message.

For multiple file attachments use -a for each file:
$ mutt -s "Subject" -a file1.tar.gz -a file2.tar.gz vivek@gmail.co.in

For more information read mutt command man page.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 4 comments… read them below or add one }

1 qp April 17, 2009

Can a mutt-1.5.19 be installed on a FreeBSD system (where there’s a mutt-1.4.2.3) by a user who doesn’t have root acccess? Using pkg_add or any other way? If so, how? Any tips appreciated. (I tried & got a lot of “permission denied.”)

Reply

2 Vivek Gite April 17, 2009

Noop. You need to be root to install software.

Reply

3 qp50cklw April 17, 2009

> Noop. You need to be root to install software.

Well, surely there must be some way for users on a FreeBSD system to install programs into their own home directory. If not, then I don’t see much “free” in FreeBSD.

Reply

4 Vivek Gite April 17, 2009

You don’t understand security concept, do you? This is a security feature. Otherwise, it will just like MS-Windows, you can install anything including virus without your permission. I suggest you get a good book which explains basic UNIX concepts.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 7 + 6 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: