2013-11-21 47 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]"