简体   繁体   English

带有附件错误的Bash Mutt电子邮件无法统计:没有这样的文件或目录

[英]Bash Mutt email with attachment error Can't stat : No such file or directory

So i,ve read some other posts and tried out the answers, but i still keep running into this problem so i wanted to post a question here and see if anyone else had any other ideas. 因此,我已经阅读了其他一些文章并尝试了答案,但是我仍然遇到这个问题,所以我想在这里发布一个问题,看看是否还有其他想法。 Keeping in mind i am pretty new to bash so i am iffy on whats available currently for what i,m looking for. 请记住,我是bash的新手,所以我对目前正在寻找的东西不满意。

I am trying to automate a process that creates a file then sends it to me. 我正在尝试自动化创建文件的过程,然后将其发送给我。 All the above is fine, until i try to automatically email myself the file. 以上所有方法都很好,直到我尝试自动通过电子邮件将文件发送给自己为止。

I have this line of code for it 我有这行代码

echo "report" | mutt -- "$USEREMAIL" -s "report" -a "my_scripts/cid_reports/trb345432.csv"

When it tries to run this command it throws an error like 当它尝试运行此命令时,将引发错误,例如

Can't stat my_scripts/cid_reports/trb345432.csv: No such file or directory my_scripts/cid_reports/trb345432.csv: unable to attach file.

Any ideas on how i can fix this? 关于如何解决此问题的任何想法? I thought mutt was good to handle this, I am going to play with the mail feature and see if i can get any success with that. 我以为mutt可以很好地处理这个问题,我将使用邮件功能,看看是否可以成功。

The system looks to be running 系统看起来正在运行

Mutt 1.4.2.2i (2006-07-14)  
Copyright (C) 1996-2002 Michael R. Elkins and others.  
Mutt comes with ABSOLUTELY NO WARRANTY; for details type `mutt -v  

The no such file or directory in general means that the file cannot be found. 通常, no such file or directory意味着找不到该文件。 Because you're using a relative path, it might be that you are in a different directory? 因为您使用的是相对路径,可能是因为您在其他目录中?

If you type cat my_scripts/cid_reports/trb345432.csv from the same directory as you run the script, is the file there? 如果您在与运行脚本相同的目录中键入cat my_scripts/cid_reports/trb345432.csv ,该文件在吗?

Or otherwise. 否则。 if you use an absolute path (usually '/home/'uid'/my_scripts/cid_reports/trb345432.csv` but your path may be duifferent), does the script find the file? 如果您使用绝对路径(通常是'/ home /'uid'/ my_scripts / cid_reports / trb345432.csv`,但路径可能不同),脚本会找到文件吗?

(or should this have been a comment in stead of an answer, eventhough it tries to guide through finding the error?) (或者,尽管它试图通过引导找到错误,但它应该是注释而不是答案)?

mutt -h

-a <file> [...] -- attach file(s) to the message

The list of files must be terminated with the "--" sequence, so, 文件列表必须以“-”序列终止,因此,

echo "hello world" | mutt -s "title" -a /home/test.txt -- ***@**.com

You need to add "--". 您需要添加“-”。

From your comments to Ljm Dullaart's answer, you're actually storing the file path in a variable, then using it something like this: 从您的评论到Ljm Dullaart的答案,您实际上是在将文件路径存储在变量中,然后使用如下所示的内容:

FILE="~/my_scripts/cid_reports/file.csv"
echo "report" | mutt -- "$USEREMAIL" -s "report" -a "$FILE"

If that's what you're doing, the problem is that ~ is in double-quotes, and therefore doesn't get expanded to the actual path to your home directory. 如果您正在执行此操作,则问题在于~放在双引号中,因此不会扩展到主目录的实际路径。 Thus, it's looking for a sub directory literally named "~" under the current working directory, and not finding it. 因此,它正在当前工作目录下寻找一个字面名为“〜”的子目录,而没有找到它。 In order for ~ to be expanded to the path to your home directory, leave it and the following / unquoted, like this: 为了将~扩展到您的主目录的路径,请保留它和以下/引号,如下所示:

file=~/"my_scripts/cid_reports/file.csv"
echo "report" | mutt -- "$useremail" -s "report" -a "$file"

Note that I've also switched the variable names to lowercase. 请注意,我还将变量名切换为小写。 This is a best practice to avoid conflicts with the various environment variables that have special meanings; 这是避免与具有特殊含义的各种环境变量冲突的最佳实践。 the special ones are all caps, so if you use lower- or mixed-case, you'll never accidentally trip over them. 特殊的都是大写字母,因此,如果使用小写或大小写混合字母,则绝不会意外绊倒它们。

SIMPLE ANSWER 简单的答案

export EMAIL="sender_mail@example.com" | mutt -e "set content_type=text/html" -s "Test Mail" -c "cc_recipient@example.com" -a /tmp/attachment.txt -- "recipient_mail@example.com" < /tmp/message.html

Please use the following syntax while attaching files with 'mutt'. 附加带有'mutt'的文件时,请使用以下语法。

 # mutt -a file -- user@domain 

For example; 例如;

 # mutt -a /tmp/test.txt -- john@abc.com 

Relevant snippets from the man page of mutt is given below. mutt手册页中的相关片段如下。

Raw -a file [...] Attach a file to your message using MIME. 原始-a文件[...]使用MIME将文件附加到您的消息中。 When attaching single or multiple files, separating filenames and recipient addresses with "--" is mandatory, 附加单个或多个文件时,必须使用“-”分隔文件名和收件人地址,

eg mutt -a image.jpg -- addr1 or mutt -a img.jpg *.png -- addr1 addr2. 例如mutt -a image.jpg-addr1或mutt -a img.jpg * .png-addr1 addr2。 The -a option must be placed at the end of command line options. -a选项必须放在命令行选项的末尾。

Ref: https://access.redhat.com/solutions/43567 参考: https : //access.redhat.com/solutions/43567

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

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