简体   繁体   English

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

[英]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. 我正在尝试制作一个bash脚本,它会向所有包含邮件和附件的联系人发送电子邮件。 This is not for malicious purposes. 这不是出于恶意目的。

How could I do this? 我怎么能这样做? Is this possible? 这可能吗? Thanks in advance. 提前致谢。

I have previously used uuencode to accomplish this: 我以前使用过uuencode来完成这个:

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

You can use this in your bash script. 您可以在bash脚本中使用它。 Sample: 样品:

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 http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.cmds/doc/aixcmds5/uuencode.htm

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

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;name1@example.com
Name2;name2@example.com"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM