Solved

Command line or script email with attachment

Posted on 2013-12-06
14
693 Views
Last Modified: 2013-12-30
I need a script which will allow me to send an email with an attachment from a MAC.
Preferably it must be a standalone script without using Apple Mail or any other email client if possible.
0
Comment
Question by:100questions
  • 7
  • 6
14 Comments
 
LVL 30

Accepted Solution

by:
renazonse earned 500 total points
ID: 39702474
You can use mutt in the command line to send email with attachments -

mutt -a file.zip -s "subject" user@company.com

You can download and install macports then run "port install mutt" to install it.
0
 
LVL 27

Expert Comment

by:tliotta
ID: 39702573
...without using Apple Mail or any other email client if possible.

As with effectively every alternative, mutt is an e-mail client. But an e-mail client is what you are asking for. The 'client' is the coding that communicates with whatever e-mail server you're sending through.

That's not all precisely accurate, but it's close enough.

Tom
0
 

Author Comment

by:100questions
ID: 39702649
Is macports free from malware and secure?
0
 
LVL 30

Expert Comment

by:renazonse
ID: 39704503
Macports is free and safe. It's the same type delivery method used in Linux environments with apt-get or yum.
0
 

Author Comment

by:100questions
ID: 39704918
I installed mutt.
Shouldn't there be some sort of configuration file stored somewhere so that when I type in a command it know which server to use etc?
0
 

Author Comment

by:100questions
ID: 39705232
I uninstalled mutt since it was giving me variable errors.
This is not a viable solution for me.
I need another method of sending an email using a script or command line.
0
 
LVL 30

Expert Comment

by:renazonse
ID: 39706229
Ok, try this one -

uuencode /Users/Renazonse/Attachment.png /Users/Renazonse/Name-of-Attachment.png | mail -s "subject of mail" email@tosendtoaddress.com

uuencode is built-in to Mac OS X. Tested an it works well.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:100questions
ID: 39706672
I will try this and will ket you know.
Does anything need to be configured - ie imap or smtp etc?
0
 
LVL 30

Expert Comment

by:renazonse
ID: 39706690
nope, it just works. The built-in mail system on the mac will use dns to send the message.
0
 

Author Comment

by:100questions
ID: 39707552
How do I just send a regular email without an attachment?
0
 
LVL 30

Expert Comment

by:renazonse
ID: 39708514
mail -s "Email Subject" email@toaddress.com -f email@fromaddress.com -F "From friendly name"

To include a body in the message you can do it like this

echo "This is the body of the message" | mail -s "Email Subject" email@toaddress.com -f email@fromaddress.com -F "From friendly name"

Body in the message and an attachment

(echo "This is the body of the message"; uuencode /Users/Renazonse/Attachment.png /Users/Renazonse/Name-of-Attachment.png) | mail -s "subject of mail" email@tosendtoaddress.com

OR

uuencode /Users/Renazonse/Attachment.png /Users/Renazonse/Name-of-Attachment.png | mail -s "subject of mail" email@tosendtoaddress.com < textfilewithbodycontents.txt
0
 

Author Comment

by:100questions
ID: 39718682
mail -s seems to send email with an address from the local mac and not from a real email address such as google and hotmail
0
 
LVL 30

Expert Comment

by:renazonse
ID: 39718691
Use the full syntax above

mail -s "Email Subject" email@toaddress.com -f email@fromaddress.com -F "From friendly name"
0
 

Author Closing Comment

by:100questions
ID: 39746712
I still need to try this to test it out, however in order for me to ask a new question, I need to close this one.  To anyone that is reading this, please test the solution, since I need to test it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Create a default user profile for Mac OS X 10.7/10.8 Create a user account on OS X that will be a template for every other user of that computer. I usually call it “profile” and make it an administrator account for the time being. 1. Install a…
In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now