Avatar of E=mc2
E=mc2
Flag for Canada asked on

Command line or script email with attachment

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.
Apple OSMac OS XSwift Programming

Avatar of undefined
Last Comment
E=mc2

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Britt Thompson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Member_2_276102

...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
E=mc2

ASKER
Is macports free from malware and secure?
Britt Thompson

Macports is free and safe. It's the same type delivery method used in Linux environments with apt-get or yum.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
E=mc2

ASKER
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?
E=mc2

ASKER
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.
Britt Thompson

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
E=mc2

ASKER
I will try this and will ket you know.
Does anything need to be configured - ie imap or smtp etc?
Britt Thompson

nope, it just works. The built-in mail system on the mac will use dns to send the message.
E=mc2

ASKER
How do I just send a regular email without an attachment?
Your help has saved me hundreds of hours of internet surfing.
fblack61
Britt Thompson

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
E=mc2

ASKER
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
Britt Thompson

Use the full syntax above

mail -s "Email Subject" email@toaddress.com -f email@fromaddress.com -F "From friendly name"
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
E=mc2

ASKER
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.