bash Mac 终端发送带附件的电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20111995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mac Terminal Sending Email With Attachment
提问by Hudson Serge
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.
我正在尝试制作一个 bash 脚本,它将向所有联系人发送一封电子邮件,其中包含一条消息和一个附件。这不是出于恶意目的。
How could I do this? Is this possible? Thanks in advance.
我怎么能这样做?这可能吗?提前致谢。
回答by Kush
I have previously used uuencode to accomplish this:
我以前使用 uuencode 来完成此操作:
uuencode source.txt destination.txt | mail -s "subject of mail" [email protected]
You can use this in your bash script. Sample:
您可以在 bash 脚本中使用它。样本:
uuencode /usr/bin/xxx.c MyFile.c | mail -s "mailing my c file" [email protected]
回答by Lri
You might also use AppleScript:
您也可以使用 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:
您可以使用显式运行处理程序从 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]"