Slim Down for Summer with That's Fit

Terminal tip: easy email attachments

If you're looking to automate the sending of emails with attachments quickly and easily (and aren't too concerned with having some glamorous stationery), Terminal is once again your friend. It's possible with Mail.app and AppleScript, but there are a few pitfalls and, for most purposes, a simple shell command will do the trick:

(echo "This is the message body";uuencode Desktop/yourDoc.doc yourDoc.doc)|mail -s "Test attachment" someone@adomain.com

The magical command in this one is uuencode, which is used to encode and decode binary files and can be used on just about any file type. The two arguments in the command above define the name and location of the source file and the name the file should have when it's received. The parenthetical statement at the beginning combines the results of the echo and uuencode commands which are then piped (|) to the mail command. The mail command, having received the body text and attachment, is told to append a subject (-s "Subject") and send it to the address specified. If you wanted to send a longer text file – with line breaks, perhaps – as the body, you could save the text in an external file and replace the echo statement with cat myfile.txt.

By adding a little complexity you could make a shell script that takes arguments, making the automation a little more flexible. But TUAW reader Adam was wondering how to send a photo he'd taken automatically using AppleScript (triggered by a Mail Rule). So here's an AppleScript implementation that doesn't require opening Terminal or dealing with Mail.app scripting:

set msgBody to "This is the body of the message"
set msgSubj to "Message subject"
set mailDest to "someone@adomain.com"
do shell script "(echo '" & msgBody & "'; uuencode /Users/you/Desktop/pictosend.jpg pictosend.jpg) | mail -s '" & msgSubj & "' " & mailDest

Make sure you remove any line breaks from that last line. This obviously requires a predetermined image name, but that could be made a variable as well and used as part of a larger script. We hope this helps, Adam!

Related Headlines

Reader Comments (Page 1 of 1)

TUAW Features

back-to-school
Mac 101 ask-tuaw
Mac News
WWDC (251)
.Mac (66)
Accessories (654)
Airport (75)
Analysis / Opinion (1432)
Apple (1702)
Apple Corporate (584)
Apple Financial (200)
Apple History (53)
Apple Professional (54)
Apple TV (164)
Audio (452)
Bad Apple (133)
Beta Beat (155)
Blogging (87)
Bluetooth (20)
Bugs/Recalls (57)
Cult of Mac (879)
Deals (226)
Desktops (116)
Developer (282)
Education (112)
eMac (10)
Enterprise (148)
Features (415)
Freeware (403)
Gaming (404)
Graphic Design (40)
Hardware (1313)
Holidays (37)
Humor (591)
iBook (66)
iLife (240)
iMac (185)
Internet (341)
Internet Tools (1347)
iTS (986)
iTunes (827)
iWork (23)
Leopard (377)
Mac mini (112)
Mac Pro (54)
MacBook (207)
MacBook Air (83)
Macbook Pro (226)
MobileMe (47)
Multimedia (461)
Odds and ends (1501)
Open Source (283)
OS (943)
Peripherals (214)
Podcasting (184)
Podcasts (95)
Portables (198)
PowerBook (136)
PowerMac G5 (51)
Retail (615)
Retro Mac (50)
Rig of the Week (42)
Rumors (649)
Software (4485)
Software Update (429)
Steve Jobs (255)
Stocking Stuffers (50)
Surveys and Polls (98)
Switchers (115)
The Woz (35)
TUAW Business (257)
Universal Binary (281)
UNIX / BSD (61)
Video (909)
Weekend Review (84)
WIN Business (47)
Wireless (89)
Xserve (39)
iPhone/iPod News
iPhone (1818)
iPod Family (2136)
App Store (173)
SDK (30)
Mac Events
One More Thing (28)
Liveblog (2)
Other Events (228)
Macworld (489)
Mac Learning
AppleScript (4)
Ask TUAW (108)
Blogs (85)
Books (26)
Books and Blogs (62)
Cool tools (453)
Hacks (473)
How-tos (491)
Interviews (44)
Mods (191)
Productivity (592)
Reviews (114)
Security (167)
Terminal Tips (71)
Tips and tricks (577)
Troubleshooting (175)
TUAW Features
iPhone 101 (36)
TUAW Labs (4)
Blast From the Past (19)
TUAW Tips (151)
Flickr Find (39)
Found Footage (90)
Mac 101 (114)
TUAW Interview (31)
Widget Watch (198)
The Daily Best (1)
TUAW Faceoff (7)

RESOURCES

RSS NEWSFEEDS

Powered by Blogsmith

Sponsored Links

The Unofficial Apple Weblog (TUAW) bloggers (30 days)

#BloggerPostsCmts
1Steven Sande4910
2Robert Palmer4931
3Cory Bohon461
4Dave Caolo340
5Erica Sadun261
6Mike Schramm250
7Michael Rose1819
8Giles Turnbull120
9Christina Warren1225
10Mat Lu114
11Brett Terpstra90
12Victor Agreda, Jr.813
13TUAW Blogger70
14Lisa Hoover32
15Joshua Ellis20
16Jason Clarke10

Featured Galleries

DNC Macs
Macworld 2008 Keynote
Macworld 2008 Build-up
Apple Vanity Plates
DiscPainter
Crash Bandicoot Nitro Kart 3D
Macworld Expo 2007 show floor
Apple Texas Hold 'Em
The Macworld Faithful in Line

 

    Most Commented On (7 days)

    Recent Comments

    More Apple Analysis

    More from AOL Money and Finance

    Other Weblogs Inc. Network blogs you might be interested in: