Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac Terminal Sending Email With Attachment

I'm trying to make a bash script that will send an email to all contacts which will contain a message and an attachment. This is not for malicious purposes.

How could I do this? Is this possible? Thanks in advance.

like image 360
Hudson Serge Avatar asked Nov 21 '13 03:11

Hudson Serge


2 Answers

You might also use AppleScript:

tell application "Mail"
    tell (make new outgoing message)
        set subject to "subject"
        set content to "content"
        -- set visible to true
        make new to recipient at end of to recipients with properties {address:"[email protected]", name:"Name"}
        make new attachment with properties {file name:(POSIX file "/tmp/test.txt")} at after the last paragraph
        send
    end tell
end tell

You can use an explicit run handler to pass arguments from a shell:

osascript -e 'on run {a}
    set text item delimiters to ";"
    repeat with l in paragraphs of a
        set {contact, address} to text items of l
    end repeat
end run' "Name1;[email protected]
Name2;[email protected]"
like image 106
Lri Avatar answered Nov 15 '22 18:11

Lri


I have previously used uuencode to accomplish this:

uuencode source.txt destination.txt | mail -s "subject of mail" [email protected]

You can use this in your bash script. Sample:

uuencode /usr/bin/xxx.c MyFile.c | mail -s "mailing my c file" [email protected]

http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.cmds/doc/aixcmds5/uuencode.htm

like image 24
Kush Avatar answered Nov 15 '22 18:11

Kush