Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Thunderbird(python,Mac):填写电子邮件、主题、正文、附加文件_Python_Macos_Email_Thunderbird - Fatal编程技术网

Thunderbird(python,Mac):填写电子邮件、主题、正文、附加文件

Thunderbird(python,Mac):填写电子邮件、主题、正文、附加文件,python,macos,email,thunderbird,Python,Macos,Email,Thunderbird,我在这里试过一些东西: 此代码片段将打开一封新电子邮件,该电子邮件将使用Thunderbird编写,但它不包含以下代码中的任何规范:电子邮件地址、主题、正文、附件,它只是一封空白的新电子邮件: import os os.system("/Applications/Thunderbird.app/Contents/MacOS/thunderbird -compose to='abc@abc.com',subject='hello',body='attached is txt file',att

我在这里试过一些东西: 此代码片段将打开一封新电子邮件,该电子邮件将使用Thunderbird编写,但它不包含以下代码中的任何规范:电子邮件地址、主题、正文、附件,它只是一封空白的新电子邮件:

import os
os.system("/Applications/Thunderbird.app/Contents/MacOS/thunderbird -compose 
to='abc@abc.com',subject='hello',body='attached is txt 
file',attachment='Users/Username/Desktop/test.txt'")
如何编写它,以便包含我传递给它的参数

更新: 好的,它主要使用这种格式,但是附件没有附加:

os.system("/Applications/Thunderbird.app/Contents/MacOS/thunderbird -compose
'to=abc@abc.edu','subject=this subject','body=this is the
body','attachment=/Users/Username/Desktop/test.txt'")
关于如何更改附件格式以使其成功附加,您有什么想法吗?这种格式没有抛出任何错误,只是没有附加文件

更新:它现在工作,我错过了一个斜杠,上面的格式现在适合我

如你所见,这

/Applications/Thunderbird.app/Contents/MacOS/Thunderbird-compose 到abc@abc.com“,subject='hello',body='attached是txt 文件',附件='Users/Username/Desktop/test.txt'

只是一个str,请删除变量,使用format,然后使用argparse捕获控制台参数:

import os
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('app', help='some help')
parser.add_argument('to', help='some help')
parser.add_argument('subject', help='some help')
parser.add_argument('body', help='some help')
parser.add_argument('attachement', help='some help')

args = parser.parse_args()

os.system("{0} -compose to={1},subject={2},body={3},attachment={4}".format(args.app, args.to, args.subject, args.body, args.attachement))
然后,将其命名为mailer.py,并与一起运行以查看帮助(如果不是您将使用它)

python mailer.py --help

现在,如果您想在python程序(例如Django)中使用它,您要做的就是用一个普通变量替换有args.*的地方。

它在Windows上对我有效,但可能缺少双引号。尝试使用:

import os
os.system("/Applications/Thunderbird.app/Contents/MacOS/thunderbird -compose 
\"to='abc@abc.com',subject='hello',body='attached is txt 
file',attachment='Users/Username/Desktop/test.txt'\"")
因为文件上说:

请注意-compose命令行选项有点复杂的语法。双引号括住传递给-compose的参数的完整逗号分隔列表,而单引号用于对同一参数的项进行分组。
希望这有帮助

你到底想要什么?你自己做了一个函数,用命令行传递参数吗?我试过了,结果还是一样,只是一封空白的新邮件。在应用程序的括号中,我把Thunderbird路径放在了前面,把目标电子邮件地址放在了双引号中,但它仍然不起作用。我需要一个新的电子邮件弹出在雷鸟和地址,主题,身体和附件都在那个里。我唯一能成功做的就是在Thunderbird中打开一封新的空白电子邮件。你是否使用了r'string?可能是因为/I认为使用r'string只会改变反斜杠的解释方式。哎呀,对不起,因为我来自windows。。。。看来我太累了,无法逻辑思考!再次抱歉为什么不使用smtplib这里是一个简单的例子,很好用。谢谢,我把完全相同的东西放进去了,它只会创建一个新的空电子邮件,我不确定其余参数的格式哪里出了问题。关于这个主题,有很多关于Windows的文档,但是关于osx的文档不多。