Send E-mail via Linux Command (Ubuntu Based)

Sometimes, we need to send email via command lines, specifically for cron jobs or bash scripts. Message and results can be sent automatically when tasks are finished. One of most popular mailing tools is gnu mailutils. Below are the brief steps to install and use mailutils.

1. install the packages:

sudo apt-get install mailutils

sudo apt-get install sharutils (if you’d like to send attachments)

In the progress, one exim4 configuration screen will be prompted out.

2. usual way to write email

mail xx@gmail.com, edit CC, subject, body, finish with ‘Ctrl-D’

3. file content as body text

mail -s test xx@gmail.com < test.txt

4. mail with attachments

uuencode attachment_name attachment_display_name | mail -s subject address

5. check whether the email has been sent out

/usr/lib/sendmail -bp

if “Mail queue is empty” is shown, then the mail has been successfully sent.

clear mail queue:

flush all: /usr/lib/sendmail -v -q [v shows the progress]

flush specific domain: /usr/lib/sendmail -v -qR[xx@gmail.com]

Advertisements

One thought on “Send E-mail via Linux Command (Ubuntu Based)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s