Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Using mail in Shell script

Hey guys,


I am writing a shell script to parse some data and create a csv file when done. I want to be able to email the csv file when the script is done. I cannot seem to figure out how to do this. I am running Mountain Lion and I have tried mail -s, mailx at the command line in Terminal and in the script and when I go check my gmail account there is no email there. Its not in the spam folders or the junk folder. Any help would be appreciated

iMac, OS X Mountain Lion, Using Terminal and a shell script

Posted on Aug 2, 2012 8:44 AM

Reply
Question marked as Best reply

Posted on Aug 2, 2012 10:10 AM

As far as I recall, the mail command does not interact with Apple's Mail program, so you would probably need to configure sendmail for it to work. It would be easier, I think, to use Applescript for that part, as it is easy to invoke Mail.

24 replies

Aug 2, 2012 12:44 PM in response to appledad05

mail(1) only writes to the local mail spool. An MTA has to be configured to deal with it. That doesn't happen by default, except for mail addressed to other users on the same host. Even then, you won't be able to read the messages in Apple Mail. You can't send MIME attachments, either. To send messages to a remote SMTP server, or to send attachments, you need a more advanced MUA such as mutt.

Aug 2, 2012 12:57 PM in response to Linc Davis

Applescript says you can put attachments in the email message:


Here is my script so far but I get the error message(error "Mail got an error: Can’t make or move that element into that container." number -10024)


///////////////////////

-- Variables

set recipientName to "some person"

set recipientAddress to "someone@gmail.com"

set theSubject to "CSV File"

set theContent to "Some content"

set fileName to choose file


-- Mail Tell Block

tell application "Mail"

--Create the message

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}

-- Set a recipient

tell theMessage

make new to recipient with properties {name:recipientName, address:recipientAddress}

tell content of theMessage

make new mail attachment with properties {name:fileName} at after the last paragraph

end tell

-- Send the Message

send

end tell

end tell

Aug 2, 2012 2:15 PM in response to Linc Davis

Thank you for your reply earlier. Sorry I know that it was an applescript. I had a suggestion to send it via applescript: Here is the script that I wrote: It will send an email but the problem is that it fails right now cause the attachment is not working correctly.


-- Variables

set recipientName to "SomeOne"

set recipientAddress to "someone@gmail.com"

set theSubject to "CSV File"

set theContent to "Here is your CSV file created from your website"

set fileName to "HD:Users:markperryman:GinaApp:gina_20120801.csv"


-- Mail Tell Block

tell application "Mail"

--Create the message

set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}

-- Set a recipient

tell theMessage

make new to recipient with properties {name:recipientName, address:recipientAddress}

tell content

make new attachment with properties {name:fileName as alias} at after the last paragraph

end tell

-- Send the Message

send

end tell

end tell


and here is the error I get now:

error "Mail got an error: Can’t make {name:alias \"HD:Users:someone:GinaApp:gina_20120801.csv\"} into type properties of attachment." number -1700 from {name:alias "HD:Users:markperryman:GinaApp:gina_20120801.csv"}


any ideas. Im at a loss right now.


I have a shell script written that does most of my process. Now I just want to write an applescript that can be called by the shell and send the email with the attachment. So Im not sure what Im doing wrong. As always any help would be appreciated.


Thanks

Aug 2, 2012 3:54 PM in response to appledad05

Using

makenewattachmentwith properties {file name:filename as alias} at after the last paragraph


works. Note that you don't wrap it in tell content ... end tell, and the property is file name not just name. It might be a good idea to put a return on your content (set theContent to "whatever you're having yourself" & return)


Message was edited by: Austin Kinsella1

Using mail in Shell script

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.