2013-11-21 43 views
6

我试图做一个bash脚本,将发送电子邮件到其中将包含一个消息和附件的所有联系人。这不是为了恶意目的。Mac的终端发送电子邮件附件随着

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

+0

在哪里“所有联系人“存储为您?这是通讯簿应用程序中的联系人吗?你有没有考虑过使用苹果脚本? – Floris

回答

9

我以前用过的uuencode来实现:

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

您可以在bash脚本使用。示例:

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

+0

我会用什么替换file.txt? 〜/路径/要/ file.txt的?为什么有两个? –

+0

对于简短的回复感到抱歉... uuencode的第一个参数是源代码,第二个参数是目标文件名....所以如果你喜欢:uuencode source.txt destination.txt | mail -s“主题”[email protected]这将把你的source.txt从本地系统发送到你的电子邮件ID,名称为file.txt – Kush

+0

谢谢。 另外,我将如何制作它,以便将电子邮件发送给我的联系人列表中的每个人? –

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:"[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 

您可以使用一个明确的运行处理程序从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]"