Commands tagged email (21)

  • This command will start a simple SMTP server listening on port 1025 of localhost. This server simply prints to standard output all email headers and the email body.


    76
    python -m smtpd -n -c DebuggingServer localhost:1025
    jemerick · 2009-02-05 16:50:44 82
  • This command uses mutt to send the mail. You must pipe in a body, otherwise mutt will prompt you for some stuff. If you don't have mutt, it should be dead easy to install.


    11
    echo "Body goes here" | mutt -s "A subject" -a /path/to/file.tar.gz recipient@example.com
    ketil · 2009-08-05 23:06:25 10
  • This is useful if you have need to do port forwarding and your router doesn't assign static IPs, you can add it to a script in a cron job that checks if you IP as recently changed or with a trigger script. This was tested on Mac OSX.


    10
    ifconfig en1 | awk '/inet / {print $2}' | mail -s "hello world" email@email.com
    rez0r · 2009-04-28 06:01:52 13
  • Checks if a web page has changed. Put it into cron to check periodically. Change http://www.page.de/test.html and mail@mail.de for your needs.


    4
    HTMLTEXT=$( curl -s http://www.page.de/test.html > /tmp/new.html ; diff /tmp/new.html /tmp/old.html ); if [ "x$HTMLTEXT" != x ] ; then echo $HTMLTEXT | mail -s "Page has changed." mail@mail.de ; fi ; mv /tmp/new.html /tmp/old.html
    Emzy · 2010-07-04 21:45:37 5
  • This is a quick and easy way of encrypting files in a datastream, without ever really creating an output file from gpg. Useful with cron also, when file(s) have to be sent based on a set schedule.


    3
    cat private-file | gpg2 --encrypt --armor --recipient "Disposable Key" | mailx -s "Email Subject" user@email.com
    slashdot · 2009-10-19 20:38:37 4
  • This depends on 'stripansi' and 'urlencode' commands, which exist on my system as these aliases: alias stripansi='perl -ple "s/\033\[(?:\d*(?:;\d+)*)*m//g;"' alias urlencode='perl -MURI::Escape -ne "\$/=\"\"; print uri_escape \$_"' The `open` command handles URLs on a Mac. Substitute the equivalent for your system (perhaps gnome-open). I don't use system `mail`, so I have this aliased as `mail` and use it this way: git show head | mail


    2
    somecommand | open "mailto:?body=$(cat - | stripansi | urlencode)"
    fletch · 2010-02-25 19:44:27 4
  • Usage: mailme message This is a useful function if you want to get notified about process completion or failure. e.g. mailme "process X completed"


    2
    mailme(){ mailx -s "$@" $USER <<< "$@"; }
    sharfah · 2011-10-07 08:55:47 5
  • Sends an email from the terminal.


    2
    wait_for_this.sh; echo "wait_for_this.sh finished running" | mail -s "Job Status Update" username@gmail.com
    mirams · 2017-02-13 18:26:37 155
  • Dumps a compressed svn backup to a file, and emails the files along with any messages as the body of the email


    1
    (svnadmin dump /path/to/repo | gzip --best > /tmp/svn-backup.gz) 2>&1 | mutt -s "SVN backup `date +\%m/\%d/\%Y`" -a /tmp/svn-backup.gz emailaddress
    max · 2010-03-08 05:49:01 6
  • This will catch most separators in the section of the email: dot . dash - underscore _ plus + (added for gmail) ... and the basic dash '-' of host names. Show Sample Output


    1
    grep -aEio '([[:alnum:]_.-\+\-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})'
    binarynomad · 2013-06-23 21:52:14 10
  • This uses mutt to send the file, and doesn't require uuencode etc


    1
    echo "This is the message body" | mutt -s "Message subject" -a file_to_attach.zip fred@example.com
    jedifu · 2013-09-26 08:05:26 7
  • Might as well include the status code it exited with so you know right away if it failed or not.


    1
    wait_for_this.sh; echo "wait_for_this.sh finished running with status $?" | mail -s "Job Status Update" username@gmail.com
    Hobadee · 2017-05-04 20:50:18 20
  • email random list can be created here: https://www.randomlists.com/email-addresses Show Sample Output


    1
    sort -t@ -k2 emails.txt
    cellcore · 2019-02-24 17:41:17 34

  • 1
    grep -Eio '([[:alnum:]_.-]{1,64}@[[:alnum:]_.-]{1,252}?\.[[:alpha:].]{2,6})'
    mikhail · 2020-07-22 22:40:33 124
  • This will email user@example.com a message with the body: "rsync done" when there are no processes of rsync running. This can be changed for other uses by changing $(pgrep rsync) to something else, and echo "rsync done" | mailx user@example.com to another command.


    0
    $(while [ ! -z "$(pgrep rsync)" ]; do echo; done; echo "rsync done" | mailx user@example.com) > /dev/null &
    matthewbauer · 2009-08-14 19:46:59 4
  • People are *going* to post the wrong ways to do this. It's one of the most common form-validation tasks, and also one of the most commonly messed up. Using a third party tool or library like exim means that you are future-proofing yourself against changes to the email standard, and protecting yourself against the fact that actually checking whether an email address is valid is *not possible*. Still, perhaps your boss is insisting you really do need to check them internally. OK. Read the RFCs. The bet before the @ is specified by RFC2821 and RFC2822. The domain name part is specified by RFC1035, RFC1101, RFC1123 and RFC2181. Generally, when people say "email address", they mean that part of the address that the RFC terms the "addr-spec": the "blah@domain.tld" address, with no display names, comments, quotes, etc. Also "root@localhost" and "root" should be invalid, as should arbitrary addressing schemes specified by a protocol indicator, like "jimbo@myprotocol:foo^bar^baz". So... With the smallest poetic license for readability (allowing underscores in domain names so we can use "\w" instead of "[a-z0-9]"), the RFCs give us: ^(?:"(?:[^"\\]|\\.)+"|[-^!#\$%&'*+\/=?`{|}~.\w]+)@(?=.{3,255}$)(?:[\w][\w-]{0,62}\.){1,128}[\w][\w-]{0,62}$ Not perfect, but the best I can come up with, and most compliant I've found. I'd be interested to see other people's ideas, though. It's still not going to verify you an address fersure, properly, 100% guaranteed legit, though. What else can you do? Well, you could also: * verify that the address is either a correct dotted-decimal IP, or contains letters. * remove reserved domains (.localhost, .example, .test, .invalid), reserved IP ranges, and so forth from the address. * check for banned domains (whitehouse.gov, example.com...) * check for known TLDs including alt tlds. * see if the domain has an MX record set up: if so, connect to that host, else connect to the domain. * see if the given address is accepted by the server as a recipient or sender (this fails for yahoo.*, which blocks after a few attempts, assuming you are a spammer, and for other domains like rediffmail.com, home.com). But these are moving well out of the realm of generic regex checks and into the realm of application-specific stuff that should be done in code instead - especially the latter two. Hopefully, this is all you needed to point out to your boss "hey, email validation this is a dark pit with no bottom, we really just want to do a basic check, then send them an email with a link in it: it's the industry standard solution." Of course, if you want to go nuts, here's an idea that you could do. Wouldn't like to do it myself, though: I'd rather just trust them until their mail bounces too many times. But if you want it, this (untested) code checks to see if the mail domain works. It's based on a script by John Coggeshall and Jesse Houwing that also asked the server if the specific email address existed, but I disliked that idea for several reasons. I suspect: it will get you blocked as a spambot address harvester pretty quick; a lot of servers would lie to you; it would take too much time; this way you can cache domains marked as "OK"; and I suspect it would add little to the reliability test. // Based on work by: John Coggeshall and Jesse Houwing. // http://www.zend.com/zend/spotlight/ev12apr.php mailRegex = '^(?:"(?:[^"\\\\]|\\\\.)+"|[-^!#\$%&\'*+\/=?`{|}~.\w]+)'; mailRegex .= '@(?=.{3,255}$)(?:[\w][\w-]{0,62}\.){1,128}[\w][\w-]{0,62}$'; function ValidateMail($address) {   global $mailRegex; // Yes, globals are evil. Put it inline if you want.   if (!preg_match($mailRegex)) {     return false;   }   list ( $localPart, $Domain ) = split ("@",$Email);   // connect to the first available MX record, or to domain if no MX record.   $ConnectAddress = new Array();   if (getmxrr($Domain, $MXHost)) {     $ConnectAddress = $MXHost;   } else {     $ConnectAddress[0] = $Domain;   }   // check all MX records in case main server is down - may take time!   for ($i=0; $i < count($ConnectAddress); $i++ ) {     $Connect = fsockopen ( $ConnectAddress[$i], 25 );     if ($Connect){       break;     }   }   if ($Connect) {     socket_set_blocking($Connect,0);     // Only works if socket_blocking is off.     if (ereg("^220", $Out = fgets($Connect, 1024))) {       fclose($Connect); // Unneeded, but let's help the gc.       return true;     }     fclose($Connect); // Help the gc.   }   return false; } Show Sample Output


    0
    perl -e "print 'yes' if `exim -bt $s_email_here | grep -c malformed`;"
    DewiMorgan · 2012-02-28 04:42:41 3

  • 0
    echo "some cool message from terminal" | mail -s "test" email@address.com
    narven · 2014-06-25 10:06:00 7
  • Poor email reputation got you down? Perhaps you're unknowingly forwarding every spam email that makes it through to info@website.com to website@gmail.com. This command outputs every forwarding address set up within a Zimbra installation.


    0
    for i in `zmprov -l gaa | cut -f2 -d"@" | uniq -c | awk '{print$2}'`; do zmprov -l gaa -v $i | grep -i zimbraPrefMailForwardingAddress; done
    skylineservers · 2014-11-17 15:24:46 8
  • Requires GNU touch. If on OSX, install coreutils and s/touch/gtouch/.


    0
    for f in `ls *.eml`; do touch -d "`grep Date: $f | head -n 1 | sed 's/.*, \(.*\) +.*/\1/'`" $f; done
    vermiculus · 2015-07-06 03:00:55 10
  • This is just a little snippit to split a large file into smaller chunks (4mb in this example) and then send the chunks off to (e)mail for archival using mutt. I usually encrypt the file before splitting it using openssl: openssl des3 -salt -k <password> -in file.tgz -out file.tgz.des3 To restore, simply save attachments and rejoin them using: cat file.tgz.* > output_name.tgz and if encrypted, decrypt using: openssl des3 -d -salt -k <password> -in file.tgz.des3 -out file.tgz edit: (changed "g" to "e" for political correctness)


    -1
    split -b4m file.tgz file.tgz. ; for i in file.tgz.*; do SUBJ="Backup Archive"; MSG="Archive File Attached"; echo $MSG | mutt -a $i -s $SUBJ YourEmail@(E)mail.com
    tboulay · 2010-03-20 16:49:19 8
  • It's very similar to this thread: http://www.commandlinefu.com/commands/view/4317/send-a-local-file-via-email mutt your@email_address.com -s "Message Subject Here" -a attachment.jpg </dev/null


    -1
    M=bob@example.com; echo "Email message" | mutt -s "Email Subject" $M
    igorfu · 2011-05-23 08:31:14 11

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

tail -f a log file over ssh into growl

dump database from postgresql to a file

Lists all usernames in alphabetical order

Keep a copy of the raw Youtube FLV,MP4,etc stored in /tmp/
Certain Flash video players (e.g. Youtube) write their video streams to disk in /tmp/ , but the files are unlinked. i.e. the player creates the file and then immediately deletes the filename (unlinking files in this way makes it hard to find them, and/or ensures their cleanup if the browser or plugin should crash etc.) But as long as the flash plugin's process runs, a file descriptor remains in its /proc/ hierarchy, from which we (and the player) still have access to the file. The method above worked nicely for me when I had 50 tabs open with Youtube videos and didn't want to have to re-download them all with some tool.

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Change the homepage of Firefox
Pros: Works in all Windows computers, most updated and compatible command. Cons: 3 liner Replace fcisolutions.com with your site name.

Copy without overwriting

Fast, built-in pipe-based data sink
This is shorter and actually much faster than >/dev/null (see sample output for timings) Plus, it looks like a disappointed face emoticon.

bash screensaver off

return the latest kernel version from a Satellite / Spacewalk server software channel


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: