Mac终端发送带附件的电子邮件

时间:2013-11-21 03:41:10

标签: macos bash email terminal

我正在尝试制作一个bash脚本,该脚本会向所有包含邮件和附件的联系人发送电子邮件。这不是出于恶意目的。

我怎么能这样做?这可能吗?提前谢谢。

2 个答案:

答案 0 :(得分:11)

我之前使用过uuencode来实现这个目标:

uuencode source.txt destination.txt | mail -s "subject of mail" youremail@yourdomain.com

您可以在bash脚本中使用它。样品:

uuencode /usr/bin/xxx.c MyFile.c | mail -s "mailing my c file" youremail@yourdomain.com

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

答案 1 :(得分:1)

您也可以使用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:"name@example.com", name:"Name"}
        make new attachment with properties {file name:(POSIX file "/tmp/test.txt")} at after the last paragraph
        send
    end tell
end tell

您可以使用显式运行处理程序从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;name1@example.com
Name2;name2@example.com"