Command line e-mail
From Cheatsheet
Contents |
Single Sendmail command
awk 'BEGIN{print "Subject:Bash rocks!\nFrom:Whoever <your@email.com>"}{printf("%s\015\n", $0)}' filecontentsforbody.txt | sendmail -t your@email.com
or
echo "text of the body of the message here" | sendmail -t "whoever@wherever.com" "subject line"
alternately if you just enter this command it will allow prompt and wait for you to type the body of the message
sendmail -t "whoever@wherever.com" "subject line"
when you're done typing, hit <return> and then type a single period, then hit <return> again and it will send
script
#!/bin/bash
FILE=$1
RECIPIENT=myemail@yahoo.com
(echo "This file $FILE was sent from Linux."
for i in `ls -1 $FILE`
do
file_name=`basename $i`
uuencode $i $file_name
done
) | mail -s "Mail sent with the attachment file: $FILE" "$RECIPIENT"
To use this script, just type in the name of the script followed by the filename
Script from command line using Mutt
http://www.cyberciti.biz/tips/sending-mail-with-attachment.html
mutt -s "Test mail" -a /tmp/file.tar.gz vivek@nixcraft.co.in < /tmp/mailmessage.txt
send via telnetting into local mailserver
this will attempt to login to your local mailserver (whether Postfix, Sendmail, Qmail, etc)
- telnet localhost 25
- starts SMTP session, hopefully allowing you to send mail
[root@server]$ telnet localhost 25 Trying 127.0.0.1... Connected to server (127.0.0.1). Escape character is '^]'. 220 localhost.localdomain; ESMTP Thu, 6 Mar 2003 17:57:01 -0500 helo localhost 250 localhost.localdomain Hello wolf [127.0.0.1], mail from: bernier@localhost 250 2.1.0 bernier@localhost... Sender ok rcpt to: robert.bernier5@sympatico.ca 250 2.1.5 robert.bernier5@sympatico.ca... Recipient ok data 354 Enter mail, end with "." on a line by itself subject; I'm hungry, send pizza Please send me one large pepperoni all dressed. Don't forget the pineapples! . 250 2.0.0 h26N3hs18884 Message accepted for delivery quit 221 2.0.0 localhost.localdomain closing connection Connection closed by foreign host.
- telnet localhost 110
- starts POP3 session, hopefully allowing you to receive mail
bash-2.05$ telnet localhost 110 Trying 127.0.0.1... Connected to localhost.localdomain Escape character is '^]'. +OK InterMail POP3 server ready. user bernier +OK please send PASS command pass 1234 +OK bernier is welcome here list +OK 1 messages retr 2 +OK 767 octets Return-Path: Received: from localhost.localdomain ([67.69.160.216]) by tomts5-srv.bellnexxia.net (InterMail vM.5.01.04.19 201-253-122-122-119-20020516) with ESMTP id <20030307030259.NLJD29897.tomts5-srv.bellnexxia.net@localhost.localdomain> for ; Thu, 6 Mar 2003 22:02:59 -0500 Received: (from bernier@localhost) by localhost.localdomain (XXX/linuxconf) id h2730mA01858 for robert.bernier5@sympatico.ca; Thu, 6 Mar 2003 22:00:48 -0500 Date: Thu, 6 Mar 2003 22:00:48 -0500 From: root Message-Id: <200303070300.h2730mA01858@localhost.localdomain> To: robert.bernier5@sympatico.ca Subject: I'm hungry send pizza Please send me one large pepperoni all dressed. Don't forget the pineapples!
