Mindbend.org

Mindblog

Welcome to my Blog!

Techblog

Information should be free, accurate, and available. I will be updating this section most often, enjoy!

Portfolio

Various galleries of artwork and photography I have done over the last five years.

Scripts

Mini scripts I have written and decided to share. Mostly oneliners for managing network and system load.

Mindware

Software projects are in the works and will be here eventually!

Contact

You can contact me through various methods.

Mailing from Command Line

Sometimes you need the ability to send email through the command line to test the mailing capacity of your system or to send yourself data quickly without having to load any bloatware.


First and foremost, there is mail which on most systems is available:

root@webserver:~# mail -s "Test Subject" root
This is a test.
.
Cc: 

This is a semi condensed way of sending an email. Notice the ( . ). When your typing a message through this fashion, the system knows you are done by detecting a stray ( . ). One thing to note, if you cut and paste a lot of data in, it could detect a stray ( . ) and then you have a malformed message. There is a better way of sending email with bulk data:

root@webserver:~# cat >> messsage.msg 
This is a test email file
I can place my message here
^d
root@webserver:~# mail -s "Test email 2" root < messsage.msg 

Notice the ^d ( control-d ), this sends an EOF signal when you are done typing out your message. The < tells bash to pipe data into mail from that file, that becomes your message. Here is what is sent by doing this:

From root@webserver Fri Apr 17 12:27:49 2009
Return-path: 
Envelope-to: root@webserver
Delivery-date: Fri, 17 Apr 2009 12:27:49 -0500
Received: from root by webserver.tld with local
        (envelope-from )
        id XXXXXX-XXXXXXX-XX
        for root@webserver; Fri, 17 Apr 2009 12:27:49 -0500
To: root@webserver
Subject: Test email 2
Message-Id: 
From: root 
Date: Fri, 17 Apr 2009 12:27:48 -0500


This is a test email file
I can place my message here

Using PHP to send mail

The fun begins. I'm quickly finding that php is just as viable as a scripting language now as it is for web development:

php -r "mail('root','Testing Subject','Test message');"

What is the point of using php? There are times when you know the email system on the server is working, but users can't send email out through php so you can easily test this process. Or you can use it to impress your friends ;)

Mailing from Command Line
Written by:Robert Church
Published on:04-17-2009

Quick Byte

support for a
deeply held American value as divisive.
-- Newt Gingrich